We have a Java backend which serves web services via WSDLs. There are some operations that return xxWSResponse with only 1 property in it: an array.
When we add service reference in Visual Studio to the web service, VS generates the code to return the array directly, not the response. If there are more properties in the response or more arrays it works like it supposed to and returns the response.
Operation sample:
<wsdl:operation name="retrieveParameterTasksList">
<wsdl:documentation> isIdempotent = NO -- TR:/retrieveParameterTasksList{retrieveParameterTasksList} -- EN:/retrieveParameterTasksList{retrieveParameterTasksList} </wsdl:documentation>
<wsdl:input message="tns:retrieveParameterTasksListRequestMsg" name="RetrieveParameterTasksListWSRequest" />
<wsdl:output message="tns:retrieveParameterTasksListResponseMsg" name="RetrieveParameterTasksListWSResponse" />
<wsdl:fault message="tns:SystemFault" name="SystemFault" />
<wsdl:fault message="tns:BusinessFault" name="BusinessFault" />
</wsdl:operation>
RetrieveParameterTasksListWSResponse:
<xsd:complexType name="RetrieveParameterTasksListWSResponse">
<xsd:sequence>
<xsd:element form="qualified" name="taskListVOs" type="this:TasksListParameterDTO" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
Auto generated code by VS:
public namespace.TasksListParameterDTO[] retrieveParameterTasksList(namespace.RetrieveParameterTasksListWSRequest RetrieveParameterTasksListWSRequest) {
namespace.RetrieveParameterTasksListWSRequest1 inValue = new namespace.RetrieveParameterTasksListWSRequest1();
inValue.RetrieveParameterTasksListWSRequest = RetrieveParameterTasksListWSRequest;
namespace.RetrieveParameterTasksListWSResponse retVal = ((namespace.WebServiceV1x0)(this)).retrieveParameterTasksList(inValue);
return retVal.RetrieveParameterTasksListWSResponse1;
}
My question: Why does Visual Studio ignores the response type and return the array in it? How can I make it return the actual response?
Thank you!
Visual Studio has created a proxy for you that will wrap the array in the correct SOAP response once it leaves your code. The correct SOAP message should still be sent by your application - have you tested what XML is returned from it?
The reason it differs from some other methods is probably due to differences in behaviour between the DataContractSerializer and the XmlSerializer. Generally Visual Studio will try to use the DataContractSerializer to generate your Service References. This won't generate Request/Response objects, instead it will generate methods that take in and return the contents of the Request/Response objects (e.g. int Multiply(int a, int b);
). However, the DataContractSerializer is more restrictive than the XmlSerializer, and sometimes Visual Studio has to fall back to the XmlSerializer. In this case, it will generate the Request/Response objects that you're seeing with everything else (e.g. MultiplyResponse Multiply(Multiply multiplyRequest);
). The same XML response should be generated regardless of which serializer Visual Studio uses.
If you need more control over the generated SOAP message, or if visual studio isn't creating the correct SOAP response, you can force Visual studio to generate full message contracts. To do this, edit the service reference, or add a new one. Click "Advanced...", then select the "Always generate message contracts" option. The message contracts are documented here: https://msdn.microsoft.com/en-us/library/ms730255.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With