如何更改此 WSDL 中的名称空间前缀?
我正在尝试为预先存在的 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 文件中更改/添加命名空间定义?
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>
</definitions>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
命名空间前缀并不重要。从 XML 规则来看,这两个示例是相同的。
The namespace prefix does not matter. The two examples are identical by the rules of XML.
命名空间前缀与变量名完全相同。您可以使用任何您想要的名称空间别名。
这类似于以下 java 代码:
在第一个 XML 中: api.fxtrade.onada onada;
在第二个 XML 中: api.fxtrade.onada m;
换句话说,第一个 XML 可以读作:
引用带有变量
onada
的“oanda.fxtrade.api
”命名空间,onada
中的create
标签code> 命名空间,将有一个值为 FXGAME 的参数。第二个 XML 可以读作:
引用带有变量
m
的“oanda.fxtrade.api
”命名空间,m
中的create
标签code> 命名空间,会有一个参数...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 variableonada
, thecreate
tag in theonada
namespace, will have a parameter of value FXGAME.The second XML can be read as:
referring to the "
oanda.fxtrade.api
" namespace with variablem
, thecreate
tag in them
namespace, will have a parameter...