简体   繁体   English

在.NET中使用RPC /编码的SOAP Web服务时出错

[英]Error Consuming a RPC/Encoded SOAP web service in .NET

I am receiving the following error when calling a web service method. 调用Web服务方法时收到以下错误。

Cannot assign object of type System.Xml.XmlNode[] to an object of type System.String. 无法将类型为System.Xml.XmlNode []的对象分配给类型为System.String的对象。

The web service is a PHP service. Web服务是一个PHP服务。 I created my proxy class using wsdl.exe from the wsdl document defined here - http://webservice.intelecast.com.au/traffic/PublicSoap/server.php?wsdl 我使用Wsdl.exe用从这里定义的WSDL文档创建了代理类- http://webservice.intelecast.com.au/traffic/PublicSoap/server.php?wsdl

Below is the proxy client method I am calling. 下面是我正在调用的代理客户端方法。

[System.Web.Services.Protocols.SoapRpcMethodAttribute("http://webservice.intelecast.com.au/traffic/PublicSoap/server.php#getAllTraffic", RequestNamespace="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php", ResponseNamespace="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php")]
 [return: System.Xml.Serialization.SoapElementAttribute("return")]
 public TmcInfo[] getAllTmcTraffic(string[] States, int[] EventCodes) {
     object[] results = this.Invoke("getAllTmcTraffic", new object[] { //Error here
                 States,
                 EventCodes});

It appear the proxy class is failing to deal with the complex types/arrays defined in the wsdl...I am unsure now how to proceed can't find a solution on the web anywhere. 看来代理类无法处理wsdl中定义的复杂类型/数组...我现在不确定如何继续在网上找不到解决方案。

Below is the SOAP response i am receiving. 以下是我收到的SOAP响应。 This all appears valid. 这一切看起来都是有效的。

<?xml version="1.0" encoding="iso-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:tns="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php">
    <SOAP-ENV:Body>
        <ns1:getAllTrafficResponse 
            xmlns:ns1="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php">
            <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:TrafficInfo[2]">
                <item xsi:type="tns:TrafficInfo">
                    <id xsi:type="xsd:string">1245632068110</id>
                    <entryDate xsi:type="xsd:datetime">22/06/2009 10:54:28</entryDate>
                    <direction xsi:type="xsd:int">0</direction>
                    <extent xsi:type="xsd:int">1</extent>
                    <locationCode xsi:type="xsd:int">31593</locationCode>
                    <countryCode xsi:type="xsd:int">4</countryCode>
                    <ltn xsi:type="xsd:int">56</ltn>
                    <diversionAdvice xsi:type="xsd:int">0</diversionAdvice>
                    <slAdvice xsi:type="xsd:int">0</slAdvice>
                    <quantifier xsi:type="xsd:int">0</quantifier>
                    <suppInfoCode xsi:type="xsd:int">0</suppInfoCode>
                    <addEvent xsi:type="xsd:int">0</addEvent>
                    <detDivAdvice xsi:type="xsd:int">0</detDivAdvice>
                    <destinations xsi:type="xsd:int">0</destinations>
                    <clSourceProblem xsi:type="xsd:int">0</clSourceProblem>
                    <eventCode xsi:type="xsd:int">802</eventCode>
                    <timeInfo xsi:type="tns:TimeInfo">
                        <start xsi:type="xsd:string">21/06/2009 14:00:00</start>
                        <finish xsi:type="xsd:string">05/11/2009 14:00:00</finish>
                        <timeZone xsi:type="xsd:string">Australia/Brisbane</timeZone>
                    </timeInfo>
                    <location xsi:type="tns:Point">
                        <lat xsi:type="xsd:float">-27.3112692120521</lat>
                        <lon xsi:type="xsd:float">153.029100894928</lon>
                    </location>
                    <additionalStreetInfo 
                      xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:AdditionalStreetInfo[1]">
                        <item xsi:type="tns:AdditionalStreetInfo">
                            <street xsi:type="xsd:string">Bracken Ridge Rd</street>
                            <type xsi:type="xsd:string">CROSS</type>
                        </item>
                    </additionalStreetInfo>
                    <address xsi:type="tns:Address">
                        <streetNumber xsi:type="xsd:string"/>
                        <streetName xsi:type="xsd:string">Bracken Ridge Rd</streetName>
                        <suburb xsi:type="xsd:string">Bracken Ridge</suburb>
                        <state xsi:type="xsd:string">QLD</state>
                    </address>
                </item>
                <item xsi:type="tns:TrafficInfo">
                    <id xsi:type="xsd:string">1245632111995</id>
                    <entryDate xsi:type="xsd:datetime">22/06/2009 10:55:11</entryDate>
                    <direction xsi:type="xsd:int">1</direction>
                    <extent xsi:type="xsd:int">1</extent>
                    <locationCode xsi:type="xsd:int">31592</locationCode>
                    <countryCode xsi:type="xsd:int">4</countryCode>
                    <ltn xsi:type="xsd:int">56</ltn>
                    <diversionAdvice xsi:type="xsd:int">0</diversionAdvice>
                    <slAdvice xsi:type="xsd:int">0</slAdvice>
                    <quantifier xsi:type="xsd:int">0</quantifier>
                    <suppInfoCode xsi:type="xsd:int">0</suppInfoCode>
                    <addEvent xsi:type="xsd:int">0</addEvent>
                    <detDivAdvice xsi:type="xsd:int">0</detDivAdvice>
                    <destinations xsi:type="xsd:int">0</destinations>
                    <clSourceProblem xsi:type="xsd:int">0</clSourceProblem>
                    <eventCode xsi:type="xsd:int">802</eventCode>
                    <timeInfo xsi:type="tns:TimeInfo">
                        <start xsi:type="xsd:string">21/06/2009 14:00:00</start>
                        <finish xsi:type="xsd:string">05/11/2009 14:00:00</finish>
                        <timeZone xsi:type="xsd:string">Australia/Brisbane</timeZone>
                    </timeInfo>
                    <location xsi:type="tns:Point">
                        <lat xsi:type="xsd:float">-27.3125370752656</lat>
                        <lon xsi:type="xsd:float">153.042898178101</lon>
                    </location>
                    <additionalStreetInfo 
                       xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:AdditionalStreetInfo[1]">
                        <item xsi:type="tns:AdditionalStreetInfo">
                            <street xsi:type="xsd:string">Bracken Ridge Rd</street>
                            <type xsi:type="xsd:string">CROSS</type>
                        </item>
                    </additionalStreetInfo>
                    <address xsi:type="tns:Address">
                        <streetNumber xsi:type="xsd:string"/>
                        <streetName xsi:type="xsd:string">Bracken Ridge Rd</streetName>
                        <suburb xsi:type="xsd:string">Bracken Ridge</suburb>
                        <state xsi:type="xsd:string">QLD</state>
                    </address>
                </item>
            </return>
        </ns1:getAllTrafficResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Is it a bug in wsdl.exe? wsdl.exe中的错误吗? I have a few unpleasant encounters with wsdl.exe . 与wsdl.exe有一些不愉快的相遇 Here are the problems outlined in my post: 这是我的帖子中概述的问题:

The first issue it fails to handle sequence with complex element. 第一个问题是它无法处理具有复杂元素的序列。 You would think that in today's webservice environment, a sequence of complex elements is a norm. 您可能会认为,在当今的Web服务环境中,一系列复杂的元素是一种规范。 But apparently Microsoft doesn't think so, and this results in inability of wsdl.exe to handle a sequence of complex elements. 但是显然微软不这么认为,这导致wsdl.exe无法处理一系列复杂元素。

What if you insist on using wsdl.exe to generate proxy class for element with a sequence of complex types? 如果您坚持使用wsdl.exe为具有一系列复杂类型的元素生成代理类怎么办? You will get a cryptic exception: unable to import binding * from namespace * - unable to import operation * - the datatype * is missing The second bug wsdl has is that it is not permissible to have two web methods that have the same return signature. 您将得到一个神秘的异常:无法从名称空间导入绑定*无法导入操作*数据类型*丢失wsdl的第二个错误是不允许两个具有相同返回签名的Web方法。 Yes, if one method returns a type of ComplexType, the other methods must have a different return type. 是的,如果一个方法返回的类型为ComplexType,则其他方法必须具有不同的返回类型。 Failing to do so will result in an System.InvalidOperationException: The XML element * from namespace * references a references a method and a type exception. 否则,将导致System.InvalidOperationException:来自命名空间的XML元素*引用了一个方法和一个类型异常。

Note that in both cases the messages are cryptic. 请注意,在两种情况下,消息都是保密的。 You won't actually know what's going on behind the hood. 您实际上将不知道引擎盖后面发生了什么。 And this is the most frustrating of all. 这是最令人沮丧的。 You don't know whether you fail because the tool is lousy, or because you are not doing things right. 您不知道是因为该工具太差还是因为操作不正确而导致失败。

Maybe you can refer to this post for an alternative of wsdl.exe. 也许您可以参考这篇文章来寻找wsdl.exe的替代方法。

It's worth noting that rpc/encoded SOAP implementation have problems on complex types. 值得注意的是,rpc /编码的SOAP实现在复杂类型上存在问题。 One way around this problem is to convert the WSDL to Document/Literal format. 解决此问题的一种方法是将WSDL转换为文档/文字格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM