xml - 如何更改此 WSDL 中的 namespace 前缀?

标签 xml soap wsdl namespaces prefix

我正在尝试为预先存在的 Web 服务创建 WSDL。我有一个现有的客户端和现有的服务器,并且我已经使用 Wireshark 捕获了两者使用的格式。我正在尝试编写一个使用相同格式的新客户端。因此,无论正确与否,我都会尽可能地匹配格式。我正在使用 XmlSPY 编写一个 WSDL 文件,然后我希望将其转换为 C# 并生成接口(interface)代码。

这是迄今为止我的 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 文件中更改/添加命名空间定义?

最佳答案

命名空间前缀并不重要。根据 XML 规则,这两个示例是相同的。

关于xml - 如何更改此 WSDL 中的 namespace 前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1944226/

相关文章:

java - 如何从 Joomla 调用外部网络服务

c# - 使用 WSDL URL 作为 Web 服务通过 ASP.NET 进行 SOAP 请求和响应?

java - XPTY0004 : Required item type of first operand of '>' is numeric; supplied value has item type xs:string

python - 父标签的子标签有特定属性值时,如何使用BeautifulSoup获取父标签名称值?

从 Web 服务引用的 C# 类未正确反序列化

java - 由 : org. apache.axis2.AxisFault 引起:无法接合模块:rampart

xml - Powershell-XML在现有部分中插入新行

web-services - 使用 Apache Camel 和 CXF 端点调用 RPC/编码的 Web 服务

java - JADE - 代理托管 Web 服务 (wsdl)

java - minOccurs、nillable 和 restriction 的目的是什么?