xml 如何更改此 WSDL 中的名称空间前缀?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1944226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I change namespace prefix in this WSDL?
提问by Stewart Loving-Gibbard
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.
我正在尝试为预先存在的 Web 服务创建 WSDL。我有一个现有的客户端和现有的服务器,并且我已经使用 Wireshark 捕获了两种使用的格式。我正在尝试编写一个使用相同格式的新客户端。因此,我试图尽可能地匹配格式,无论是否正确。我正在使用 XmlSPY 编写一个 WSDL 文件,然后我希望将其用于 C# 并生成接口代码。
Here is my WSDL so far:
到目前为止,这是我的 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>
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:
以下是 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>
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.
我现在的问题是 - 如何匹配原始客户端生成的“oanda:”前缀?这就是所谓的命名空间前缀吗?我生成的代码中的“m:”来自哪里?我可以在本网站的其他示例中找到对此的提及,但没有使用 WSDL,至少据我所知。
Thank you for any help you can give.
感谢您提供的任何帮助。
When I try to run the above WSDL through svcutil.exe, I get two problems.
当我尝试通过 svcutil.exe 运行上述 WSDL 时,我遇到了两个问题。
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.
1) XML 格式不正确,因为同名的参数不能超过一个。XMLSpy 也抱怨这个,所以我现在通过将它们重命名为 Parameter1 和 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:
2)一旦超过这个,我就会收到这个错误:
"Namespace prefix 'tns:oanda' is not defined."
“未定义命名空间前缀 'tns:oanda'。”
So, again: How do I change/add a namespace definition in a WSDL file?
所以,再说一遍:如何在 WSDL 文件中更改/添加名称空间定义?
回答by John Saunders
The namespace prefix does not matter. The two examples are identical by the rules of XML.
命名空间前缀无关紧要。这两个示例在 XML 规则上是相同的。
回答by CMR
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:
这类似于以下 java 代码:
In the first XML: api.fxtrade.onada onada;
In the second XML: api.fxtrade.onada m;
在第一个 XML 中:api.fxtrade.onada onada;
在第二个 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 createtag in the onadanamespace, 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 createtag in the mnamespace, will have a parameter...
换句话说,第一个 XML 可以读作:
引用oanda.fxtrade.api带有变量的“ ”命名空间,命名空间中onada的create标签onada,将有一个值为 FXGAME 的参数。
第二个 XML 可以读作:
引用oanda.fxtrade.api带有变量的“ ”命名空间,命名空间中m的create标签m,将有一个参数...

