Dela via


Adding a Custom Resolver to a PeerChannel Application

By default, PeerChannel uses the Peer Name Resolution Protocol (PNRP) peer resolver service. However, due to network policy or configuration, it can be necessary to implement a custom peer resolver service. The section below descibes the process for adding a custom peer resolver service to a PeerChannel appplicaiton.

Custom Peer Resolvers

A custom peer resolver service is a singleton service that caches the mesh IDs and the endpoint addresses in a dictionary and responds to the registration, unregistration, and resolves requests from the clients. Mesh IDs are expected to be unique. If multiple applications use the same resolver, they should choose different mesh IDs to avoid conflict.

Creating and Configuring a Custom Peer Resolver

A custom peer resolver implements a static main function to create a ServiceHost for the given CustomPeerResolverService type. The host is also responsible for providing a base address to the service host, which must be configured in the application settings in the configuration file (usually titled App.config).

<appSettings>
    <!-- use appSetting to configure base address provided by host -->
    <add key="baseAddress"
     value=" net.tcp://localhost/servicemodelsamples/peerResolverService" />
</appSettings>

The custom peer resolver service implements the ICustomPeerResolver contract, which exposes the RegisterMeshId, UnregisterMeshId, and ResolveMeshId operations. The client makes synchronous requests to a given operation and the service replies with the result.

The service exposes a single endpoint for communicating with the service that is defined using the configuration file. The binding is configured with a standard NetTcpBinding, which provides TCP communication.

<services>
    <service 
       service="Microsoft.ServiceModel.Samples. CustomPeerResolverService">
       <!-- use base address provided by the host -->
       <endpoint address=""
            binding=" netTcpBinding "
             contract="Microsoft.ServiceModel.Samples. ICustomPeerResolver" />
    </service>
</services>

For clients on remote machines to access the service, a qualified domain name must be specified instead of localhost.

Note that clients using a custom resolver must have some upper bound on client-server latency in order to successfully refresh their registration with the peer resolver service.

See Also

Concepts

Extending PeerChannel


© 2007 Microsoft Corporation. All rights reserved.