WCF Services—Understanding Service Contracts
|Visual C# Tutorials|
|.NET Framework Tutorials|
|© 2007 Chris Peiris, Dennis Mulder|
Understanding Service Contracts
Service contracts, one of the Cs in the ABCs of WCF, are what are advertised to the consumers of your services. This advertisement generally takes place through a schema and a contract definition that supports a standardized method for publishing the service contract (along with data contracts). Today, that schema is either a Web Services Description Language (WSDL) contract or a WS-MetadataExchange (MEX) contract. These formats are industry-supported, open specifications. These specifications are located at the following locations:
|WSDL AND WS-METADATAEXCHANGE|
| WSDL is an XML Schema–based description of supported operations and messages for an endpoint.
MEX represents a message exchange protocol that allows the discovery of WSDL, WS-Policy, or XML Schema associated with a target namespace. More information is available at the following location:
Note For COM interop, a third type of contract exists—a typed contract.
The service is basically that, a service—something, perhaps a behavior, that takes place on behalf of another system. Services themselves can be a variety of types and generally fall into either informational or action oriented.
Platform and framework vendors have implemented the tools and libraries that can leverage these standardized contracts to provide a more seamless integration experience amongst the service provider and the consumers (sometimes referred to as receivers and senders). This is what WCF provides in its metadata model: the ability to both define and publish as well as consume these standardized schema definitions. It is possible, in WCF, to provide that support both programmatically at runtime and declaratively at design and configuration time.
WCF provides the standards and tools support primarily through
SvcUtil.exe. This utility is the primary code and metadata interpretation tool. That, in combination with the WCF framework’s ability to leverage reflection to interrogate types adorned with the appropriate attributes, makes generating and using the WCF framework less complicated than before. Figure 4-1 illustrates how service metadata is consumed by
SvcUtil.exe for proxy generation; additionally, the same metadata is leveraged by the WCF framework for runtime interaction.