Problems with a C # .NET client using an external PHP SOAP web service that returns hash arrays

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

I can successfully create a web link in VS2010 using the WSDL address provided to me, and using the script, I see that the expected XML gets sent and received. However, .NET seems to have a problem parsing the returned XML.

The simplest web service I'm dealing with just accepts an array of usernames and is designed to return some nested hash arrays of users (each user has their own name, type, etc.) and an array of errors (for any usernames that do not match). The documentation that I described in "PHP-ish":

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

I get an XML SOAP that will match 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 created for me based on WSDL says that it returns a plain old string , which suggests that it cannot handle how WSDL determines the return type.

Full WSDL is available here:

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

Here is an example of the sent and returned XML from 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 the answer is:

 <?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.

+4
source share
2 answers

There was the same problem. All I had to do was fix every namespace from https to http in the generated cs file. Therefore, it may be the wrong namespace.

+1
source

Source: https://habr.com/ru/post/1345637/


All Articles