我正在尝试为预先存在的 Web 服务创建 WSDL。我有一个现有的客户端和现有的服务器,并且我已经使用 Wireshark 捕获了两者都使用的格式。我正在尝试编写一个使用相同格式的新客户端。因此,我试图尽可能地匹配格式,无论它是否正确。我正在使用 XmlSPY 编写一个 WSDL 文件,然后我希望将其带到 C# 并生成接口代码。
到目前为止,这是我的 WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.ecerami.com/wsdl/HelloService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ecerami.com/wsdl/HelloService.wsdl" name="HelloService">
<message name="api:create"/>
<message name="oanda:create">
<part name="parameter"/>
<part name="parameter"/>
</message>
<portType name="Oanda_PortType">
<operation name="create">
<input message="tns:oanda:create"/>
<output message="tns:api:create"/>
</operation>
</portType>
<binding name="Oanda_binding" type="tns:Oanda_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="create">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body use="encoded" namespace="oanda.fxtrade.api"/>
</input>
<output>
<soap:body use="encoded" namespace="oanda.fxtrade.api"/>
</output>
</operation>
</binding>
<service name="Oanda_service">
<documentation>WSDL File for Oanda FX Trade API (local SOAP server)</documentation>
<port name="Oanda_port" binding="tns:Oanda_binding">
<soap:address location="http://10.0.0.3:18081"/>
</port>
</service>
</definitions>
这是我要复制的示例消息。这是原始客户端发出的内容:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<oanda:create xmlns:oanda="oanda.fxtrade.api">
<parameter>FXGAME</parameter>
<parameter></parameter>
</oanda:create>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是 XmlSPY 所说的我的 WSDL 将为同一消息发出的内容:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:create xmlns:m="oanda.fxtrade.api">
<parameter/>
<parameter/>
</m:create>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我现在的问题是 - 我如何匹配原始客户端生成的“oanda:”前缀?这就是所谓的命名空间前缀吗?我生成的代码中的“m:”来自哪里?我可以在此站点的其他示例中找到对此的提及,但至少据我所知,没有使用 WSDL。
感谢您提供的任何帮助。
当我尝试通过 svcutil.exe 运行上述 WSDL 时,我遇到了两个问题。
1) XML 格式不正确,因为您不能有多个具有相同名称的参数。XMLSpy 也对此有所抱怨,因此我暂时将其重命名为 Parameter1 和 Parameter2。
具体错误是:“指定了多个名为“参数”的消息部分。每个消息部分必须有一个唯一的名称。”
2)一旦过去,我得到这个错误:
“未定义命名空间前缀 'tns:oanda'。”
所以,再一次:如何在 WSDL 文件中更改/添加命名空间定义?