0

我有一个需要通过 SOAP 端点 (wsHttpBinding) 和 REST 端点 (webHttpBinding) 公开的 WCF 服务。我在相关属性中包含了名称和命名空间以帮助进行版本控制(tempuri.org 应该从 WSDL 中完全删除)。出于某种原因,如果我不在 webHttpBinding 端点上添加 bindingNamepace 属性,它会在 WSDL 中添加 tempuri.org 命名空间。示例 WSDL 输出如下。

没有 bindingNamespace 的 WSDL -

<wsdl:definitions name="State" targetNamespace="http://example.com/services/masterdat/state/2012/02/05" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:tns="http://example.com/services/masterdata/state/2012/02/05" 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:i0="http://tempuri.org/"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" 
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">

带有 bindingNamespace 的 WSDL -

<wsdl:definitions name="State" targetNamespace="http://example.com/services/masterdata/state/2012/02/05" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:tns="http://example.com/services/masterdata/state/2012/02/05" 
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsa10="http://www.w3.org/2005/08/addressing" 
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" 
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">

这是我的端点的 web.Config。我正在使用 WCFExtras 来展平我的 WSDL(因此 wsHttpBinding 端点上的行为配置),但没有它的行为是相同的。

<services>
  <service name="MasterDataExample.Services.StateService">
    <!--  bindingConfiguration="defaultWsBinding" -->
    <endpoint address="soap"
              behaviorConfiguration="flatWsdl"
              binding="wsHttpBinding"
              bindingNamespace="http://example.com/services/masterdata/state/2012/02/05"
              contract="MasterDataExample.Services.IStateService" 
              name="soap" />
    <!--  -->
    <endpoint address="json"
              behaviorConfiguration="json"
              binding="webHttpBinding"
              bindingNamespace="http://example.com/services/masterdata/state/2012/02/05"
              contract="MasterDataExample.Services.IStateService" 
              name="ajax" />
  </service>
</services>

我已经在我的解决方案中加载了 WCFExtras 并查看了 WsdlExporter 以查看是否可以找到 tempuri.org 的提及但没有成功。我还使用 XSharper.Core 转储对象图以查看是否可以找到它。它不在那里。

有谁之前经历过这个吗?作为一种解决方法,我将在 webHttpBinding 端点上包含 bindingNamespace 以保持 WSDL 干净,但我想知道为什么会发生这种情况。

谢谢!

4

1 回答 1

3

似乎端点配置中需要 BindingNamespace 才能从 WSDL 中完全删除 tempuri.org 命名空间。请参阅这篇文章(第 3 项)。

于 2012-04-27T18:51:29.457 回答