views:

1821

answers:

1

In working with another company I'm trying to write a SOAP client to talk to their service. The service itself has no wsdl-files but I've managed to successfully write my own proxy class inheriting from SoapHttpClientProtocol. Basic methods that only return an integer or a single value is not a problem but when I try to make a method that needs to parse results returned in an array I just can't get it to work. Part of the problem might be that the SOAP-result references a namespace that does not exist anymore but setting the

 [SoapRpcMethodAttribute("Action", Use = SoapBindingUse.Literal)]

on the method seems to overlook the namespace issue. However, whenever I try to parse the result into an array I just get a null result back.

[SoapRpcMethodAttribute("Action", Use = SoapBindingUse.Literal)]
[return: XmlArrayAttribute("Result")]
public ComplexType[] getArray(int customerId, int subCustomerId, int subscriptionId, int type)
{
    object[] result;
    result = Invoke("getArray", new object[] { id });
    return ((ComplexType[])(result[0]));
 }

Am I totally wrong in thinking that the above method should work?

XML Result from the server looks like this (inside the body):

<getArray SOAP-ENC:root="1">
 <Result SOAP-ENC:arrayType="ns1:SOAPStruct[1]" xsi:type="SOAP-ENC:Array" xmlns:ns1="http://soapinterop.org/xsd"&gt;
  <item>
   <id xsi:type="xsd:integer">60</id>
   <name xsi:type="xsd:string">John</name>
   <type xsi:type="xsd:string">1</type>
  </item>
  <item>
   <id xsi:type="xsd:integer">99</id>
   <name xsi:type="xsd:string">Jane</name>
   <type xsi:type="xsd:string">1</type>
  </item>
 </Result>
</getArray>

And the namespace isssue is that http://soapinterop.org/xsd does not exist anymore it seems but that's not the main problem.

+1  A: 

That SOAP array is an rpc/encoded response, you'll need to make sure you're setting all the attributes on your client class/methods so that the stack knows its handling an rpc/encoded response. (the Use=...Literal is definitely wrong).

What does your c# definition of ComplexType look like? You probably need to set the type namespace on it, e.g. [System.Xml.Serialization.SoapTypeAttribute(Namespace="http://soapinterop.org/xsd")]

superfell