Contract Queries

Sometimes the client needs to programmatically verify whether a particular endpoint (identified by its address) supports a particular contract. For example, imagine an application where the application administrator (or even the end user) specifies or configures the application during setup (or at runtime) to consume and interact with a service. If the service does not support the required contracts, the application should alert the user that an invalid address was specified, and ask for an alternative or a correct address. For example, the Credentials Manager application used in Chapter 10 has just such a feature: the user needs to provide it with the address of the security credentials service that manages account membership and roles. Credentials Manager only allows the user to select a valid address, after verifying that the address supports the required service contracts.

Programmatic Metadata Processing

In order to support such functionality, the application needs to retrieve the service’s metadata and see if at least one of the endpoints supports the requested contract. As explained in Chapter 1, the metadata may be available either in special metadata exchange endpoints (if the service supports them), or over the HTTP-GET protocol. When you use HTTP-GET, the address of the metadata exchange is the HTTP-GET address suffixed by ?wsdl. To ease the task of parsing the returned metadata WCF offers a few helper classes, available in the System.ServiceModel.Description ...

Get Programming WCF Services, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.