title: Problems with C# .NET client using external PHP SOAP web service which returns hash arrays
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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':</p>
  
  <pre><code>array (
    'users' =&gt; array (
      array(
        'id' =&gt; 11,
        'username' =&gt; 'mick',
        'firstname' =&gt; 'Mick',
        'lastname' =&gt; 'Byrne'
      ),
      ...
    )
    'errors' =&gt; array(
      array(
        'username' =&gt; 'whoever',
        'errorcode' =&gt; 'NOSUCHUSER'
      )
    )
  )
  </code></pre>
  
  <p>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:</p>
  
  <p><code>Cannot assign object of type System.Xml.XmlNode[] to an object of type System.String.</code></p>
  
  <p>Interestingly, the corresponding method that .NET has created for me based on the WSDL says it returns a plain old <code>string</code> which suggests that it can't handle the way the WSDL defines the return type.</p>
  
  <p>The full WSDL is available here:</p>
  
  <p><a href="http://www.elearning.psychology.org.au/webservice/soap/server.php?wsdl=1&amp;wstoken=dc45858adb6f28b7feae87014d46d9b3" rel="nofollow">http://www.elearning.psychology.org.au/webservice/soap/server.php?wsdl=1&amp;wstoken=dc45858adb6f28b7feae87014d46d9b3</a></p>
  
  <p>Here is a sample of the sent and returned XML from the this basic Get Usernames request:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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"&gt;
      &lt;soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
          &lt;tns:netspot_user_get_users_by_username&gt;
              &lt;usernames href="#id1" /&gt;
          &lt;/tns:netspot_user_get_users_by_username&gt;
          &lt;soapenc:Array id="id1" soapenc:arrayType="xsd:string[1]"&gt;
              &lt;Item&gt;557788&lt;/Item&gt;
          &lt;/soapenc:Array&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>And response:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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/"&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;ns1:netspot_user_get_users_by_usernameResponse&gt;
              &lt;return xsi:type="ns2:Map"&gt;
                  &lt;item&gt;
                      &lt;key xsi:type="xsd:string"&gt;errors&lt;/key&gt;
                      &lt;value SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array"&gt;
                          &lt;item xsi:type="ns2:Map"&gt;
                              &lt;item&gt;
                                  &lt;key xsi:type="xsd:string"&gt;username&lt;/key&gt;
                                  &lt;value xsi:type="xsd:string"&gt;557788&lt;/value&gt;
                              &lt;/item&gt;
                              &lt;item&gt;
                                  &lt;key xsi:type="xsd:string"&gt;errorcode&lt;/key&gt;
                                  &lt;value xsi:type="xsd:string"&gt;NOSUCHUSER&lt;/value&gt;
                              &lt;/item&gt;
                          &lt;/item&gt;
                      &lt;/value&gt;
                  &lt;/item&gt;
              &lt;/return&gt;
          &lt;/ns1:netspot_user_get_users_by_usernameResponse&gt;
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>