开发者

How can I change namespace prefix in this WSDL?

I am trying to create a WSDL for a pre-existing web service. I have an existing client and and existing server, and I've captured the format both use using Wireshark. I am trying to write a new client that uses the same format. Therefore I am trying to match the format as closely as possible, be it correct or not. I'm cooking up a WSDL file using XmlSPY, which I hope then to take to C# and generate interface code.

Here is my WSDL so far:

<?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>
</d开发者_运维技巧efinitions>

Here is a sample message I'm trying to copy. This is what the original client emits:

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

Here is what XmlSPY says my WSDL will emit for the same message:

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

My question for now is - how do I match the "oanda:" prefix generated by the original client? Is this what is called a namespace prefix? Where is the "m:" in my generated code coming from? I can find mentions of this in other examples on this site, but none using WSDL, at least as far as I can tell.

Thank you for any help you can give.


When I try to run the above WSDL through svcutil.exe, I get two problems.

1) the XML is not well-formed since you can't have more than one parameter with the same name. XMLSpy was also complaining about this, so I punted on it for now by renaming them to Parameter1 and Parameter2.

The specific error is: "More than one message part named 'parameter' was specified. Each message part must have a unique name."

2) Once past this, I get this error:

"Namespace prefix 'tns:oanda' is not defined."

So, again: How do I change/add a namespace definition in a WSDL file?


The namespace prefix does not matter. The two examples are identical by the rules of XML.


Namespace prefixes are exactly like variable names. You can alias the namespace with whatever you wish to.

This is analogous to the following java code:

In the first XML: api.fxtrade.onada onada;
In the second XML: api.fxtrade.onada m;

In other words, the 1st XML can be read as:
referring to the "oanda.fxtrade.api" namespace with variable onada, the create tag in the onada namespace, will have a parameter of value FXGAME.
The second XML can be read as:
referring to the "oanda.fxtrade.api" namespace with variable m, the create tag in the m namespace, will have a parameter...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜