How to: Map a Policy to a Web Service

The following procedure details how to apply a policy to SOAP messages sent to or received by a specific endpoint.

To map the Web service to the named policy in the policy file

  1. Add a <mappings> Element element under the <policyDocument> Element element.

  2. Add an <endpoint> Element element under the <mappings> Element element for each service in the application. In addition, you can add the <defaultEndpoint> Element element for all unmapped endpoints.

  3. Add an <operation> Element element under the <endpoint> Element element for each operation in the service. In addition, you can add the <defaultOperation> Element element for all unmapped operations.

    The <defaultOperation> Element element signifies that the policy is mapped to all unmapped operations for that endpoint. To apply the policy to a particular action within a service (sometimes referred to as a method, Web method, or function), use the <operation> Element element.

  4. Add the <request> Element (WSE for Microsoft .NET), <response> Element (WSE for Microsoft .NET), and <fault> Element elements to map policies for those messages.

Example

The following code example specifies that all request messages to the service timestamp.asmx is mapped to the policy message-agein the file policyCache.xml. It also specifies that no policy is required for response messages or fault messages from this service.

<?xml version="1.0" encoding="utf-8" ?>
<policyDocument xmlns="https://schemas.microsoft.com/wse/2003/06/Policy">
  <mappings xmlns:wse="https://schemas.microsoft.com/wse/2003/06/Policy">
    <endpoint uri="https://localhost/timestamp.asmx">
      <defaultOperation>
        <request policy="#message-age" />
        <response policy=""/>
        <fault policy=""/>
      </defaultOperation>
    </endpoint>
  </mappings>
  <policies>
  </policies>
</PolicyDocument>

See Also

Tasks

How to: Create a Policy File
How to: Declare a Policy

Concepts

Policy Overview

Other Resources

Configuring a Web Service's Policy