4

I am writing a .NET web application that needs to call external webservices. The documentation I have been provided with includes code examples in PHP.

I can successfully create a web reference in VS2010 using the WSDL address that has been provided to me, and using fiddler I can see that the expected XML is getting sent and received. However .NET appears to be having trouble parsing the returned XML.

The simplest web service I'm dealing with just accepts an array of usernames and is meant to return some nested hash arrays of users (with each user it's own array name, type, etc. fields) and an array of errors (for any usernames that didn't match up). The documentation I have describes it in 'PHP-ish':

array (
  'users' => array (
    array(
      'id' => 11,
      'username' => 'mick',
      'firstname' => 'Mick',
      'lastname' => 'Byrne'
    ),
    ...
  )
  'errors' => array(
    array(
      'username' => 'whoever',
      'errorcode' => 'NOSUCHUSER'
    )
  )
)

I'm getting the SOAP XML that would correspond to this. However, when .NET tries to turn it into a result it throws an exception:

Cannot assign object of type System.Xml.XmlNode[] to an object of type System.String.

Interestingly, the corresponding method that .NET has created for me based on the WSDL says it returns a plain old string which suggests that it can't handle the way the WSDL defines the return type.

The full WSDL is available here:

http://www.elearning.psychology.org.au/webservice/soap/server.php?wsdl=1&wstoken=dc45858adb6f28b7feae87014d46d9b3

Here is a sample of the sent and returned XML from the this basic Get Usernames request:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.elearning.psychology.org.au/webservice/soap/server.php?wstoken=dc45858adb6f28b7feae87014d46d9b3" xmlns:types="http://www.elearning.psychology.org.au/webservice/soap/server.php?wstoken=dc45858adb6f28b7feae87014d46d9b3/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <tns:netspot_user_get_users_by_username>
            <usernames href="#id1" />
        </tns:netspot_user_get_users_by_username>
        <soapenc:Array id="id1" soapenc:arrayType="xsd:string[1]">
            <Item>557788</Item>
        </soapenc:Array>
    </soap:Body>
</soap:Envelope>

And response:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.elearning.psychology.org.au/webservice/soap/server.php?wstoken=dc45858adb6f28b7feae87014d46d9b3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:netspot_user_get_users_by_usernameResponse>
            <return xsi:type="ns2:Map">
                <item>
                    <key xsi:type="xsd:string">errors</key>
                    <value SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
                        <item xsi:type="ns2:Map">
                            <item>
                                <key xsi:type="xsd:string">username</key>
                                <value xsi:type="xsd:string">557788</value>
                            </item>
                            <item>
                                <key xsi:type="xsd:string">errorcode</key>
                                <value xsi:type="xsd:string">NOSUCHUSER</value>
                            </item>
                        </item>
                    </value>
                </item>
            </return>
        </ns1:netspot_user_get_users_by_usernameResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Any help would be greatly appreciated.

Nhan Nguyen
  • 410
  • 2
  • 12
Mick Byrne
  • 14,394
  • 16
  • 76
  • 91
  • Seeing the WSDL and/or SOAP message would be helpful. – JohnOpincar Mar 29 '11 at 02:11
  • Good point, they're now added in. – Mick Byrne Mar 29 '11 at 02:22
  • I've found some other StackOverflow issues that appears to be very similar to mine, though none have any kind of practical solution, such as [this RPC related one](http://stackoverflow.com/questions/1463655/error-consuming-a-rpc-encoded-soap-web-service-in-net) and [another specifically about WSDL arrays](http://stackoverflow.com/questions/618736/soap-wsdl-associative-arrays) and [another about PHP webservices consumed in .NET](http://stackoverflow.com/questions/1102020/consuming-php-webservicesoap-wsdl-from-asp-net-c-app-problems-with-array). – Mick Byrne Mar 29 '11 at 03:44

1 Answers1

1

Had the same problem. All I had to do is fix every namespace from https to http in generated cs file. So, it could be your namespaces are wrong.

Vladimir Kocjancic
  • 1,814
  • 3
  • 22
  • 34