我有一个外部xml文件,它声明了WS-policy,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<wsp:Policy xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsrr="http://www.ibm.com/xmlns/prod/serviceregistry/6/2/wspolicy"
xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"
wsrr:policyClassDomain="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" targetNamespace="http://mycommon/Policy">
<wsp:Policy wsu:Id="WSHttpsBinding_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<wsaw:UsingAddressing />
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsp:Policy wsu:Id="WSHttpBinding_policy">
<wsp:ExactlyOne>
<wsp:All>
<wsaw:UsingAddressing />
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsp:Policy wsu:Id="basicHttpsBinding_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsp:Policy wsu:Id="TcpBinding_policy">
<wsp:ExactlyOne>
<wsp:All>
<msb:BinaryEncoding xmlns:msb="http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1" />
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<msf:WindowsTransportSecurity xmlns:msf="http://schemas.microsoft.com/ws/2006/05/framing/policy">
<msf:ProtectionLevel>EncryptAndSign</msf:ProtectionLevel>
</msf:WindowsTransportSecurity>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<wsaw:UsingAddressing />
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</wsp:Policy>
如何将其链接到为我的服务生成的WSDL文档?
答案 0 :(得分:1)
我认为您搜索此处所述的“外部政策附件”:http://www.w3.org/TR/ws-policy-attach/#ExternalPolicyAttachment
答案 1 :(得分:0)
从生成的WSDL链接外部WS-Policy需要什么?除非它与您的绑定中的WCF安全设置相匹配(在这种情况下,它已经包含了所需的策略元素),这实际上并不起作用。
如果您仍然热衷于将外部ws-policy强制转换为生成的WSDL,那么实现它的方法将是使用自定义IWsdlExportExtension实现。
答案 2 :(得分:0)
要在您的WSDL文档上拥有<wsp:Policy..
,您必须首先在Web配置文件中使用HTTPS绑定。
因此,如果您使用https,则可以添加
服务节点中的基地址:
<baseAddresses>
<add baseAddress="http://yourdomain.com/"/>
<add baseAddress="https://yourdomain.com/"/>
</baseAddresses>
然后添加基本的HTTPS绑定节点:
<basicHttpsBinding>
<binding name="BasicHttpsBinding_Name">
<security>
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpsBinding>
你也应该像以下那样删除终点:
<endpoint address="" binding="basicHttpsBinding"
bindingConfiguration="BasicHttpsBinding_Name"
contract="NameSpace.Name" name="BasicHttpsBinding_Name" />
通过编译您的服务,策略节点将出现在您的WSDL上。
我希望它可以帮到你。