添加SOAP元素的命名空间

时间:2017-03-31 10:55:00

标签: c# web-services soap

使用SoapUI测试SOAP Web服务时,该工具会生成以下soap信封:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:v2="http://xmlns.mydomain.com/sales/schema/quotation/v2">
  <soapenv:Header/>
  <soapenv:Body>
    <v2:AddUpdateQuotationRequest>
      <v2:UserId>UserId</v2:UserId>
      <v2:PublicQKey>8de6cf8d-ea38-434d-a636-aac3a1c45999</v2:PublicQKey>
    </v2:AddUpdateQuotationRequest>
  </soapenv:Body>
</soapenv:Envelope>

但是当我在Visual Studio中添加对Web服务的引用并测试Web服务时,soap信封缺少命名空间并具有以下格式:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <AddUpdateQuotationRequest>
      <UserId>UserId</UserId>
      <PublicQKey>8de6cf8d-ea38-434d-a636-aac3a1c45999</PublicQKey>
    </AddUpdateQuotationRequest>
  </s:Body>
</s:Envelope>

我知道相应于此article,可以在通过实现IClientMessageInspector创建soap消息后添加命名空间。

话虽如此,这是我的两个问题:

  1. 为什么从SoapUI生成的soap信封与使用Visual Studio生成的信封不同?
  2. 是否有其他/更简单的方法将名称空间添加到soap消息中,然后按上述链接中的说明实现IClientMessageInspector

0 个答案:

没有答案