开发者

How to put WS-Policy in WSDL document

I have an external xml file which declare WS-policy as shown below:

<?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> 

How can I link it 开发者_高级运维to the WSDL document generated for my service?


I think you search for "External Policy Attachment" described here: http://www.w3.org/TR/ws-policy-attach/#ExternalPolicyAttachment


What do you need to link an external WS-Policy from the generated WSDL? Unless it matches your WCF security settings in your binding (in which case, it would already be including the required policy elements in it), that's not really going to work.

If you're still keen on forcing the external ws-policy into the generated WSDL, the way to do it would be with a custom IWsdlExportExtension implementation.


To have the <wsp:Policy.. on your WSDL doc you must have the HTTPS binding on your web config file first.

so if you are using https then you could add

a base address in you service node:

      <baseAddresses>
        <add baseAddress="http://yourdomain.com/"/>
        <add baseAddress="https://yourdomain.com/"/>
      </baseAddresses>

then add basic HTTPS binding node:

  <basicHttpsBinding>
    <binding name="BasicHttpsBinding_Name">
      <security>
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </basicHttpsBinding>

also you should have end-point decleared like below:

  <endpoint address="" binding="basicHttpsBinding" 
            bindingConfiguration="BasicHttpsBinding_Name"
            contract="NameSpace.Name" name="BasicHttpsBinding_Name" />

and by compiling your service the policy node will appear on you WSDL.

I hope it helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜