So far in this chapter,i has shown you different ways to create services,
How to expose a service endpoint and metadata exchange endpoint,
How to generate client proxies,
How to work with metadata,
And how to configure service behaviors.
In this section,i ' ll place the emphasis on endpoints,binding configuration,and allocation of assemblies for a more complex Solution.
WCF includes a number of standard bindings this allow you to quickly configure a service for a particular set of PROTOC Ols.
clients must use compatible protocols if they communicate with each endpoint.
Services can expose multiple endpoints for the same service contract on order to expose functionality over different p Rotocols. The
for Example,a service is called by internal clients through tcp,but by external clients over HTTP.
In addition to supporting different protocols,internal and external clients could not have access to the same service co Ntracts.
Some operations May is allowed only by clients within the Domain,while others is publicly available to remote clients On the Internet.
In this lab you'll configure multiple endpoints for a service-to-support different endpoint and binding configurations.
In the process you ll explore the following concepts:
Hosting Multiple services
Configuring multiple endpoints for a service
Accessing a service from a Windows client application
initializing proxies from multiple endpoint and binding configurations
comparing proxy generation to sharing types between services and clients
Lab:hosting multiple Services and sharing Types
In this lab,you ' ll modify an existing solution to implement a service contract and an administrative contract on both DiSTI NCT Services.
You'll then host each service in the same host Process,a console application.
An internal client presumed to be behind the firewall would consume each service using network protocols such as TCP and NA Med pipes.
This client'll has access to service operations exposed by the service contract and administrative contract.
An external client,presumed to being accessing the service over the Internet would have access only to operations exposed by T He service contract over HTTP.
The internal client would share class libraries to access service Contracts,while the external client would use traditional Methods for generating service proxies.
implementing multiple contracts on a service
in this section,you ' re going to implement the Predefin Ed service contracts on distinct services.
Each service would expose, Contracts:one, functionality core to the service,the, and for Administrativ E functionality.
Both Services would implement the same administrative contract.
This illustrates a example of contract factoring for reuse.
1. Start by opening the solution <yourlearningwcfpath>\labs\chapter1\multicontractservice\ MultiContractService.sln.
This solution contains several shell projects,including a service library,a Host,and Dows client applications as follows:
Businessservicecontracts
A class library containing three contracts:iadmin, Iservicea,and Iserviceb.
Iadmin defines administrative operations.
Iservicea and ISERVICEB respectively describe functionality to being exposed by ServiceA and SERVICEB.
Businessservices
A class library that would contain the Services:servicea and SERVICEB.
Host
A Console application that would host ServiceA and ServiceB.
Internalclient
A Windows client application that would access services behind the firewall.
Externalclient
A Windows client application that would access services over the Internet.
Note:putting service contracts into a separate class library facilitates sharing metadata with client applications when yo U own both sides of the development effort.
2. The first thing you ' ll ' provide a implementation for Servicea,which are located in the Businessservices class Libr ary.
First,take a look at the contracts you'll implement.
Go to the Businessservicecontracts project and open IServiceA.cs; You'll see a contract with a operations.
Now open IAdmin.cs and you'll see the another contract with the different operations.
To implement these contracts,go to the Businessservices project.
First,add a reference to the Businessservicecontracts project so you can access the contracts it defines.
Then open ServiceA.cs and add a using statement for the Businessservicecontracts namespace, as shown here:
using businessservicecontracts;
Modify the definition of servicea so, it derives from Iservicea and iadmin as follows:
Public class Servicea:iservicea, Iadmin
Implement both contracts implicitly.
You can use a shortcut by hovering your mouse over iservicea and using the smart tag to select "Implement interface Iservi CeA, "as shown in Figure 1-29."
Learning WCF Chapter1 exposing multiple Service endpoints