2009-12-22 50 views
1

我正在嘗試爲預先存在的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文件中更改/添加名稱空間定義?

回答

4

命名空間前綴無關緊要。這兩個例子與XML的規則相同。

+0

這可能是真的,但我'd仍然想改變命名空間前綴。當然有一種方法可以控制它,是的? – 2009-12-22 15:50:40

1

命名空間前綴與變量名完全相同。你可以用任何你想要的名字空間來別名。

這類似於下面的Java代碼:

在第一XML:api.fxtrade.onada onada;
在第二個XML中:api.fxtrade.onada m;

換句話說,所述第一XML可以讀作:
提到「oanda.fxtrade.api」命名空間具有可變onada,在onada命名空間中的標籤create,將具有值FXGAME的參數。
第二XML可以理解爲:
指具有可變m的「oanda.fxtrade.api」的命名空間,在m命名空間中的create標籤,將有一個參數...