This article is 1st part of multi series article on WCF 4.0. This article will list all the new feature of WCF and also will explain in detail Dynamic Service and End Point Discovery feature of WCF 4.0.
What are the new in WCF 4.0?
I am listing here, new features in WCF 4.0
- Dynamic Service and End Point discovery
- Intermediate Routing Pattern ( Generic Routing Services)
- Discovery announcement
- Simplified Configuration
- Protocol bridging and Fault tolerance
- Standard End Points.
- .svc-less activation of REST services or making REST URI nice.
I will discuss details of each feature in subsequent articles. This article is emphasizing on Dynamic Service and End Point discovery. So please tune in.
Dynamic Service and End Point discovery
People say; you need to know only ABC of a service to expose End Point of that service. And client or service consumer needs to know only End Point to consume the service. But wait for a while here, and think; what if? Binding need to change at the service side from basic to WS over HTTP, This is very basic change but to accommodate this client has to update the service again. And this is very much error prone. It is very tedious task to update client about all the basic frequent change at the service side. To solve this issue, there should be some mechanism and that is called End Point Discovery or Dynamic Service.
In absolute technical words
WCF 4.0 supports WS –Discovery standard or protocol.
- This is a multicast protocol that issues SOAP message over UDP,
- WS-Discovery is a Standard that defines a lightweight discovery mechanism for discovering services based on multicast messages. It enables a service to send a Hello announcement message when it is initialized and a Bye message when is removed from the network.
- Client or consumer can discover services by multicasting a Probe message to which a service can reply with a ProbeMatch message containing the information necessary to contact the service.
- Client or consumer can find services that have changed endpoint by issuing a Resolve message to which respond with a ResolveMatchmessage.
So, we can say WS –Discovery is a UDP based multicast message exchange. This message receives End Point information from Service and uses this as discovery information. Client uses discovery information to discover the available service on the network.
WCF Service Discovery API
WCF provides, WCF Discovery API for dynamic publish and discovery of web service using WS –Discovery protocol. This API helps service to publish them and helps client to find service on the network.
- In managed mode there is a centralized server called a discovery proxy that services use to publish themselves and clients use to retrieve information about available services.
- When a new service starts up it sends an announcement message to the discovery proxy.
- The discovery proxy saves information about each available service to storage.
- When a client must search for a service it sends a Probe request to the discovery proxy and it determines whether any of the services that have been published match the request.
- If there are matches the discovery proxy sends a ProbeMatch response back to the client.
- The client can then contact the service directly using the service information returned from the proxy.
- There is no centralized server.
- Service announcements and client requests are sent in a multicast fashion.
- If a service is configured to send out a Hello announcement on start up, it sends it out over a well-known, multicast address using the UDP protocol.
- Therefore, clients have to actively listen for these announcements and process them accordingly.
- When a client issues a Probe request for a service it is also sent over the network using a multicast protocol.
- Each service that receives the request determines whether it matches the criteria in the Probe request and responds directly to the client with a ProbeMatch message if the service matches the criteria specified in the Probe request.
In this sample, we will create a very basic service and at the client side, first client will discover the service in Ad-Hoc mode and then consume that.
To run and go through this sample, you need Visual Studio 2010 Beta.
To make a service discoverable, a ServiceDiscoveryBehavior must be added to the service host and a discovery endpoint must be added to specify where to listen for and send discovery message
Open VS2010. Create a new project. Select project type as Web. From Web Project type choose WCF Service Application Project template
Delete all the code which is generated by Visual studio. After deleting Contract and Service Implantation is as follows.
The above is simple Service Contract and implantation of that.
Open Web.Config file. And modify the System.ServiceModel. Add the code which in red rectangle below.
<!– Service Endpoints –>
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
<!– To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment –>
<!– To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information –>
Explanation of Config file
- One new End Point is being added.
- Kind of newly added End Point is udpDiscoveryEndpoint.
- This End Point will be used to discover the service.
- ServiceDiscovery behavior is also get added.
Press F5 to run the service. Service will get hosted in ASP.Net web server.
Add a new console project in solution. Add Reference of System.ServiceModel.Discovery.dll in console project.
Add namespace using System.ServiceModel.Discovery;
Explanation of the code
- We are making object of DiscoveryClient class. This class is user to discover available service.
- In constructor of this class, we are passing UdpDiscoveryEndPoint of the service.
- Then we are calling Find method with contract name as argument to get FindResponse.
- Now FindResponse variable having all the available address for contract passed in Find method.
- We are creating the client proxy and passing discovered address as argument.
- Calling the service operation on the client proxy.
In this article, I talked about what are the new features in WCF 4.0. I went into details of Dynamic Service and End Point Discovery. In later articles, I will cover in detail other features as well. Till then, thanks for reading.
Leave a Reply