我正在尝试为预先存在的Web服务创建一个WSDL。我有一个现有的客户端和现有的服务器,并且我已经捕获了使用Wireshark的格式。我正在尝试编写一个使用相同格式的新客户端。因此,我试图尽可能匹配格式,无论是否正确。我正在使用XmlSPY编写一个WSDL文件,我希望这个文件可以带到C#并生成接口代码。如何在此WSDL中更改命名空间前缀?
这是迄今为止我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文件中更改/添加名称空间定义?
这可能是真的,但我'd仍然想改变命名空间前缀。当然有一种方法可以控制它,是的? – 2009-12-22 15:50:40