【问题标题】:What's the problem with this web service method?这种网络服务方法有什么问题?
【发布时间】:2009-12-23 14:34:02
【问题描述】:

更新:Problem solved


我必须调用一个 Web 服务方法 (dduLogin),它返回 3 个参数。我通过 Visual Studio “添加 Web 引用”生成了代码。这是 wsdl 的相关部分:

<message name="dduLoginRequest">
    <part name="Ticket" type="xsd:string"/>
    <part name="ServiceId" type="xsd:string"/>
    <part name="Market" type="xsd:string"/>
    <part name="Application" type="xsd:string"/>
    <part name="Brand" type="xsd:string"/>
    <part name="Sincom" type="xsd:string"/>
    <part name="CertificationSystem" type="xsd:string"/>
</message>  


<message name="dduLoginResponse">
    <part name="Ticket" type="xsd:string"/>
    <part name="LoginId" type="xsd:string"/>
    <part name="Return" type="xsd:string"/>
</message>
<portType name="dduPortType">
    <operation name="dduLogin">
        <input message="tns:dduLoginRequest"/>
        <output message="tns:dduLoginResponse"/>
    </operation>


</portType>
<binding name="dduBinding" type="tns:dduPortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="dduLogin">
        <soap:operation soapAction="urn:ddu#dduLogin" style="rpc"/>
        <input>
            <soap:body use="encoded" namespace="urn:ddu" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
            <soap:body use="encoded" namespace="urn:ddu" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
    </operation>


</binding>

可以调用这个方法,返回的就是这个xml:

<SOAP-ENV:Body><ns1:dduLoginResponse xmlns:ns1="urn:ddu">
    <Ticket xsi:type="xsd:string">M-S%40%2AT6%2F%26179G%23%24%25%25%2A%40%40LDNT%27BP%3F9C%2CRY9-Z8C0C%3D0JXD%24_%2A%5EFKF%26DV%3BIP_8%3DM.E3VBDU7%3CAB%5C9_%22%3A%29E9%2CYO6%5C8I%5D6J%5EZ%60%2C8%3A%26%60%25U%3B.6A4G%2BO%5EQA%5DINI4X2%247%29M%2C%3B%3DZ%5CQ%3C%3A%27%3AB%5CSUB%3F9GAPC%3DRV%3CA%5E%2CE7%40L3%3F%3FY%215T%27%40B%3FKUJIH%3D%2B150Q%3CD%3A%3B%21D%22%3B%3ED%60%60%0A</Ticket>
    <LoginId xsi:type="xsd:string">22459</LoginId>
    <Return xsi:type="xsd:string">0</Return></ns1:dduLoginResponse>
</SOAP-ENV:Body>

但是在调用之后,并不是所有的返回值都被填满。这是 Visual Studio 为该方法生成的代码:

[System.Web.Services.Protocols.SoapRpcMethodAttribute("urn:ddu#dduLogin", RequestNamespace="urn:ddu", ResponseNamespace="urn:ddu")]
[return: System.Xml.Serialization.SoapElementAttribute("LoginId")]
public string dduLogin(ref string Ticket, string ServiceId, string Market, string Application, string Brand, string Sincom, string CertificationSystem, out string Return) {
    object[] results = this.Invoke("dduLogin", new object[] {
        Ticket,
        ServiceId,
        Market,
        Application,
        Brand,
        Sincom,
        CertificationSystem});
    Ticket = ((string)(results[1]));
    Return = ((string)(results[2]));
    return ((string)(results[0]));
}

好像结果顺序不对(ticket应该是results[0]),LoginId应该是results[1]results[1]也是空的(null)。

这里有什么问题?我错过了什么吗?这是一个坏的wsdl吗?它是 Visual Studio Web 服务代理生成器吗?以前有人有这个吗?有关如何解决此问题的任何建议?

顺便说一句,一位同事能够使用另一个 Web 服务工具集(完全与 .NET 无关)成功调用此 Web 服务。

编辑:这里是 wsdl.exe 的输出,用于相关 wsdl:

C:\temp>wsdl https://eu.link.fiatauto.com/tsi/DDUWsAut.php?wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Warning: This web reference does not conform to WS-I Basic Profile v1.1.
R2706: A wsdl:binding in a DESCRIPTION MUST use the value of "literal" for the u
se attribute in all soapbind:body, soapbind:fault, soapbind:header and soapbind:
headerfault elements.
  -  Input element soapbind:body of operation 'dduLogin' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduLogin' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduLogout' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduLogout' on portType 'dduBindi
ng' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduDir' on portType 'dduBinding'
from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduDir' on portType 'dduBinding'
 from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduGetGroupList' on portType 'ddu
Binding' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduGetGroupList' on portType 'dd
uBinding' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduGetGroupFileList' on portType
'dduBinding' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduGetGroupFileList' on portType
 'dduBinding' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduCreate' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduCreate' on portType 'dduBindi
ng' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduOpen' on portType 'dduBinding'
 from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduOpen' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduClose' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduClose' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduAbort' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduAbort' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduRead' on portType 'dduBinding'
 from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduRead' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduWrite' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduWrite' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduGet' on portType 'dduBinding'
from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduGet' on portType 'dduBinding'
 from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduPost' on portType 'dduBinding'
 from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduPost' on portType 'dduBinding
' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduGetAtt' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduGetAtt' on portType 'dduBindi
ng' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduPostAtt' on portType 'dduBindi
ng' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduPostAtt' on portType 'dduBind
ing' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduTransaction' on portType 'dduB
inding' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduTransaction' on portType 'ddu
Binding' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduCommit' on portType 'dduBindin
g' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduCommit' on portType 'dduBindi
ng' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduRollback' on portType 'dduBind
ing' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduRollback' on portType 'dduBin
ding' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduLoginDescr' on portType 'dduBi
nding' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduLoginDescr' on portType 'dduB
inding' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduIsRemoteDebug' on portType 'dd
uBinding' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduIsRemoteDebug' on portType 'd
duBinding' from namespace 'urn:ddu'.
  -  Input element soapbind:body of operation 'dduLogClient' on portType 'dduBin
ding' from namespace 'urn:ddu'.
  -  Output element soapbind:body of operation 'dduLogClient' on portType 'dduBi
nding' from namespace 'urn:ddu'.

For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.

Writing file 'C:\temp\ddu.cs'.

更新

我遵循了@Benjamin's 的建议,并使用 WCF 创建了一个客户端。不过我确实遇到了一些问题:wsdl 包含一些不应该有空格的空格,而且服务的编码显然是 ISO-8859-1,所以我最终创建了自己的CustomTextMessageEncoder

由于我预计此服务会出现更多问题,因此我仍然非常有兴趣让它与旧式 Web 服务引用一起使用,所以如果有人知道为什么返回的 xml 解析不正确, 这里是 wsdl 的 url:

https://eu.link.fiatauto.com/tsi/DDUWsAut.php?wsdl

请注意,删除空格(这是我在尝试服务引用方式时遇到的问题)没有解决了这个问题(wsdl.exe 的输出在没有空格的情况下仍然相同)。

【问题讨论】:

    标签: c# web-services wsdl


    【解决方案1】:

    我有类似的问题,当我使用 WCF(即:添加服务引用而不是 Web 引用)生成代理类时它们消失了。

    【讨论】:

    【解决方案2】:

    您可以尝试使用 wsdl.exe 工具来创建代理类文件,而不是使用“添加引用”。如果您在使用代理类时遇到相同的缺少返回值问题,您可以尝试手动编辑代理类文件来解决您的问题。

    wsdl.exe http://msdn.microsoft.com/en-us/library/7h3ystb6%28VS.80%29.aspx

    您的问题可能与此博文中描述的问题类似。 http://blogs.msdn.com/eugeneos/archive/2007/02/05/solving-the-disappearing-data-issue-when-using-add-web-reference-or-wsdl-exe-with-wcf-services.aspx

    【讨论】:

    • 其中一个结果为空(null),但它应该包含一个值。这不是手动编辑生成的代理类可以解决的问题。
    【解决方案3】:

    我向服务提供商提出了这个问题,经过一番故障排除(他们无法首先重现它),很明显,同一个服务显然有 2 个不同的端点:

    我使用的默认设置:

    https://eu.link.fiatauto.com/tsi/DDUWsAut.php

    以及他们正在使用的另一个(显然是专门针对 dotnet 客户端):

    https://eu.link.fiatauto.com/tsi/DDUWsAutDotNet.php

    我仍然不清楚为什么需要这样做,但使用 dotnet 特定端点代替另一个端点解决了我的问题,所以我没有再问任何问题。

    【讨论】:

    • 这是必需的,因为他们的服务不符合 WS-I BP 1。RPC/Encoded(他们使用的样式)会产生模棱两可的消息,因此不应使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    • 2012-04-08
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    相关资源
    最近更新 更多