gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:50 24 4
gpt4 key购买 nike

我在调用 Web 服务方法时收到以下错误。

无法将 System.Xml.XmlNode[] 类型的对象分配给 System.String 类型的对象。

Web 服务是一个 PHP 服务。我使用此处定义的 wsdl 文档中的 wsdl.exe 创建了我的代理类 - http://webservice.intelecast.com.au/traffic/PublicSoap/server.php?wsdl

下面是我调用的代理客户端方法。

[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});

代理类似乎无法处理 wsdl 中定义的复杂类型/数组...我现在不确定如何继续在网上找不到解决方案。

下面是我收到的 SOAP 响应。这一切似乎都有效。

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

最佳答案

它是 wsdl.exe 中的错误吗?我有几个unpleasant encounters with wsdl.exe .以下是我的帖子中概述的问题:

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. But apparently Microsoft doesn't think so, and this results in inability of wsdl.exe to handle a sequence of complex elements.

What if you insist on using wsdl.exe to generate proxy class for element with a sequence of complex types? 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. Yes, if one method returns a type of ComplexType, the other methods must have a different return type. Failing to do so will result in an System.InvalidOperationException: The XML element * from namespace * references a references a method and a type exception.

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.

或许可以引用this post wsdl.exe 的替代品。

关于c# - 在 .NET 中使用 RPC/编码的 SOAP Web 服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1463655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com