Handling Multiple Contracts with Indigo - Sharing Service Contracts
(Page 3 of 4 )
This lab illustrates an alternate approach for sharing metadata with the client. Instead of generating a proxy using SvcUtil, a class library containing only service contracts is shared by the service library and the internal client application. This approach is useful in an environment where you own both sides: client and service. This approach can simplify steps in development, help you avoid the internal complexity of types generated by SvcUtil, and even allow you to exercise more control over service contract versioning on both ends.
Realistically, remote clients such as Internet clients may not be owned, which is why the more traditional approach of sharing contracts via add service reference is used.
Duplicating Operations
This lab illustrates exposing two different contracts on each service. These contracts each have unique operations: a set for the business functionality exposed by the service, and a set for administrative functions. You may also want to expose a subset of business operations for external clients while exposing the complete set of business functionality to internal clients.
To achieve this, you could create internal and external interfaces for the service contract, for example:IServiceAandIInternalServiceA. The external interface,IServiceA, would in this case contain a subset of the functionality exposed byIInternalServiceA(see Example 1-28).
Example 1-28. Internal and external service contracts with duplicate operations
[ServiceContract(Namespace = http://www.thatindigogirl.com/samples/2006/06)] public interface IServiceA
{
[OperationContract]
string Operation1();
[OperationContract]
string Operation2();
}
[ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")] public interface IInternalServiceA
{
[OperationContract]
string Operation1();
[OperationContract]
string Operation2();
[OperationContract]
string Operation3();
}
If you expose each of these contracts on their own service types (ServiceAandInternalServiceA, respectively), external clients will never see the functionality exposed to internal clients because they work from a different WSDL document. However, the implementation can still be the same for each service implementation.
The following sample illustrates the scenario:<YourLearningWCFPath>\ ServiceContracts\ Samples\ InternalExternalServiceTypes.sln.
Next: Summary >>
More BrainDump Articles
More By O'Reilly Media
|
This article is excerpted from chapter 1 of the book Learning WCF A Hands-on Guide, written by Michele Leroux Bustamante (O'Reilly, 2007; ISBN: 0596101627). Check it out today at your favorite bookstore. Buy this book now.
|
|