Extension Codeunit (Web Service Call) returning Array instead of expected type

I have written an extension codeunit to the customer card which returns a BigDecimal. Here is the function source.

PROCEDURE CustomerSalesToDate@1000000001(Cust@1000000000 : Record 18) ToDateSales : Decimal;

BEGIN

WITH Cust DO BEGIN

IF CurrentDate <> WORKDATE THEN BEGIN

CurrentDate := WORKDATE;

END;

SETRANGE(“Date Filter”,0D,CurrentDate);

CALCFIELDS(“Sales (LCY)”);

EXIT(“Sales (LCY)”);

END;

END;

All WDSL tools show that the operation should return a BigDecimal (not an array of BigDecimals).

<xsd:element minOccurs=“1” maxOccurs=“1” name=“return_value” type=“xsd:decimal” />

</xsd:sequence>

</xsd:complexType>

</xsd:element>


But when I call the service I receive a BigDecimal Array size 2 with both values being the same (correct amount that I was looking for).

Even stranger, I coded a function to return an array of BigDecimals (similar to the values customer stats calculates) and instead of an array of 5 BigDecimals, I received an array of 10 BigDecimals with each value paired up!

I’m coding in Java (on a Mac with the Eclipse IDE), and I am also calling the NAV services dynamically (no stubs) but I don’t think that has anything to do with the problem. Has any of my C# brethren run across this problem? Does this happen on the .net side of the house as well? If so, maybe it is an undocumented feature that the NAV team has implemented (as a double check that the correct value was received).

I can hack around the problem by multiplying my index by 2 to get the value I am looking for, but something must be wrong on my end, or the NAV end.

Here is the operation description (AXIS) I am using for each of the two functions:

public void initializeCustomerSalesToDateOperation() throws Exception{

// Customer Sales Operation (Returns Customer Sales for a date period for the customer key)

// Check the binding to make sure the anticipated operation exists and is consistent with our understanding

BindingOperation bindingOperation = navBinding.getBindingOperation(“CustomerSalesToDate”,“CustomerSalesToDate”, “CustomerSalesToDate_Result”);

if (bindingOperation == null){

customerSalesToDateOperation = null;

return;

}

// Build the Operation

OperationDesc oper = new OperationDesc();

oper.setName(“CustomerSales”);

// Set the Input Parameters

ParameterDesc param;

param = new ParameterDesc(new QName(nameSpaceUri, “cust”),

org.apache.axis.description.ParameterDesc.IN,

new javax.xml.namespace.QName(“XML Schema”, “string”),

java.lang.String.class, false, false);

oper.addParameter(param);

// Set the Return Type

oper.setReturnType(new QName(“XML Schema”, “decimal”));

oper.setReturnClass(java.math.BigDecimal.class);

oper.setReturnQName(new QName(nameSpaceUri,“return_value”));

oper.setStyle(org.apache.axis.constants.Style.WRAPPED);

oper.setUse(org.apache.axis.constants.Use.LITERAL);

customerSalesToDateOperation = oper;

}

public void initializeCustomerStatsOperation() throws Exception{

// Customer Stats Operation (Returns Customer Stats for a date period for the customer key)

// Check the binding to make sure the anticipated operation exists and is consistent with our understanding

BindingOperation bindingOperation = navBinding.getBindingOperation(“CustomerStats”,“CustomerStats”, “CustomerStats_Result”);

if (bindingOperation == null){

customerStatsOperation = null;

return;

}

// Build the Operation

OperationDesc oper = new OperationDesc();

oper.setName(“CustomerStats”);

// Set the Input Parameters

ParameterDesc param;

param = new ParameterDesc(new QName(nameSpaceUri, “cust”),

org.apache.axis.description.ParameterDesc.IN,

new javax.xml.namespace.QName(“XML Schema”, “string”),

java.lang.String.class, false, false);

oper.addParameter(param);

param = new ParameterDesc(new QName(nameSpaceUri, “_CustDateChoice”),

org.apache.axis.description.ParameterDesc.IN,

new javax.xml.namespace.QName(“XML Schema”, “int”),

java.lang.String.class, false, false);

oper.addParameter(param);

// Set the Return Type

oper.setReturnType(new QName(“XML Schema”, “decimal”));

oper.setReturnClass(java.math.BigDecimal.class);

oper.setReturnQName(new QName(nameSpaceUri,“return_value”));

oper.setStyle(org.apache.axis.constants.Style.WRAPPED);

oper.setUse(org.apache.axis.constants.Use.LITERAL);

customerStatsOperation = oper;

}

Here are the actual calls

/****************************************************************

*** CustomerStats - Extended (Codeunit) Method to retrieve ***

*** the values of flow fields from a customer ***

*** parameter - key - a key from a retrieved ***

*** instance of a Customer (WMSNavRecordObject). ***

*** User supplies an int that indicates the period ***

*** to Filter Sales on ***

*** 0 = Current Accounting Period ***

*** 1 = This Fiscal Year ***

*** 2 = Last Fiscal Year ***

*** @throws AxisFault ***

  • @throws Exception ***

****************************************************************/

public ArrayList customerStats (String key, int dateSelection) throws AxisFault, Exception{

cardPageCall.setOperation(customerStatsOperation);

cardPageCall.setUseSOAPAction(true);

cardPageCall.setSOAPActionURI(nameSpaceUri + “:CustomerStats”);

cardPageCall.setEncodingStyle(null);

cardPageCall.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);

cardPageCall.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);

cardPageCall.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);

cardPageCall.setOperationName(new javax.xml.namespace.QName(nameSpaceUri, “CustomerStats”));

try {

java.lang.Object _resp = cardPageCall.invoke(new java.lang.Object {key, dateSelection});

if (_resp instanceof java.rmi.RemoteException) {

throw (java.rmi.RemoteException)_resp;

}

else {

// extractAttachments(cardPageCall);

try {

ArrayList respArray = (ArrayList) _resp;

if (respArray.get(0) instanceof BigDecimal) return (ArrayList)respArray;

else return null;

} catch (java.lang.Exception _exception) {

System.out.println("Exception on bdArray Assignment: "+ _exception);

return null;

}

}

} catch (org.apache.axis.AxisFault axisFaultException) {

throw axisFaultException;

} catch (RemoteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

/**********************************************************************

*** CustomerSalesToDate - Extended (Codeunit) Method to retrieve ***

*** the value of flow field Sales To Date from a customer ***

*** parameter - key - a key from a retrieved ***

*** instance of a Customer (WMSNavRecordObject). ***

*** @throws AxisFault ***

  • @throws Exception ***

*********************************************************************/

public BigDecimal customerSalesToDate (String key) throws AxisFault, Exception{

cardPageCall.setOperation(customerSalesToDateOperation);

cardPageCall.setUseSOAPAction(true);

cardPageCall.setSOAPActionURI(nameSpaceUri + “:CustomerSalesToDate”);

cardPageCall.setEncodingStyle(null);

cardPageCall.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);

cardPageCall.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);

cardPageCall.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);

cardPageCall.setOperationName(new javax.xml.namespace.QName(nameSpaceUri, “CustomerSalesToDate”));

try {

java.lang.Object _resp = cardPageCall.invoke(new java.lang.Object {key});

if (_resp instanceof java.rmi.RemoteException) {

throw (java.rmi.RemoteException)_resp;

}

else {

// extractAttachments(cardPageCall);

try {

ArrayList respArray = (ArrayList) _resp;

if (respArray.get(0) instanceof BigDecimal) return (BigDecimal)respArray.get(0);

else return new BigDecimal(0);

} catch (java.lang.Exception _exception) {

return (BigDecimal) org.apache.axis.utils.JavaUtils.convert(_resp, BigDecimal.class);

}

}

} catch (org.apache.axis.AxisFault axisFaultException) {

throw axisFaultException;

} catch (RemoteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

Any insight would be appreciated…