Search code examples
c#web-serviceswcfwsdlpolicy

How to implement Policy in WCF web service?


I want to create a web service that does the same as the given web service depending on the service description language only. I managed to create the same exact service, except for this part of the meta-data:

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

What is that? and how it can be generated in the service description language?


Solution

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

    To have the <wsp:Policy.. on your WSDL doc you should 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.
    Also see some solution here
    I hope it helps you.