本文介绍了使用它返回的哈希阵列外部PHP SOAP Web服务使用C#.NET客户端问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了需要调用外部web服务一个.NET Web应用程序。我已经提供了该文档包含在PHP中code的例子。

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.

我可以成功地创建使用已提供给我的WSDL地址,并使用招我可以看到预期的XML是越来越发送和接收在VS2010的Web引用。但是.NET似乎遇到了麻烦解析返回的XML。

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.

最简单的Web服务我处理只不过是接受用户名数组,是为了回报广大用户的一些嵌套哈希数组(每个用户的它自己的数组名,类型等领域)和错误的数组(任何用户名不匹配起来)。我该文档描述了它的PHP杂交:

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'
    )
  )
)

我收到这将对应于这个SOAP XML。然而,当.NET试图把它变成一个结果,它抛出一个异常:

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:

无法指定类型System.Xml.XmlNode []的对象System.String类型的对象。

有趣的是,.NET为我创造的基础上的WSDL的相应方法说,它返回一个普通的老式字符串这表明它不能处理的方式, WSDL定义的返回类型。

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.

完整的WSDL可以在这里找到:

The full WSDL is available here:

<一个href="http://www.elearning.psychology.org.au/webservice/soap/server.php?wsdl=1&wstoken=dc45858adb6f28b7feae87014d46d9b3" rel="nofollow">http://www.elearning.psychology.org.au/webservice/soap/server.php?wsdl=1&wstoken=dc45858adb6f28b7feae87014d46d9b3

下面是示例的发送和从这个基本的获取用户名请求返回的XML:

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>

和响应:

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

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

推荐答案

这些可以帮助:

http://social.msdn.microsoft.com/Forums/en/asmxandxml/thread/f550e2b2-af9e-4653-a618-cffffdc70fdf

http://bytes.com/topic/net/answers/426522-system-invalidcastexception-cannot-assign-object-type-system-xml-xmlnode-object-type-system-string

这篇关于使用它返回的哈希阵列外部PHP SOAP Web服务使用C#.NET客户端问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:17