Introduction
This sample demonstrates how to use WCF (Windows Communication Foundation) to develop a typical client server application using TCP/IP binding. You may refer to several tutorials to get an introduction to WCF. The purpose of this article is to demonstrate a sample implementation of client server application using WCF and TCP/IP binding.
About this WCF Sample
This sample is a typical client server application, which includes a client that need to login first before it can access other components on the server.
The client application uses a login screen where user can input user id and password. When you login, the user id and password will be validated by calling corresponding services on the server. Once authenticated, an authentication token will be returned from the server. Client stores this token in a custom context on the client.
After authenticating, the authentication token is sent from the client to the server as a custom Header along with each request made to the server. Server retrieves this token from the headers and validates against a custom database.
This sample includes 2 solutions:
1. WCF Host 2. WCF Client
As the name indicates, the first solution represents a windows applications which hosts the WCF server components.
The second solution represents the client application which communicates with the server.
The Server project has 2 important manager classes:
1. UserManager - This class provides the services to authenticate user on the server side using user id and password. Also, returns a custom token to the client so that client need to pass only this authentication for any service calls. 2. SomeOtherManager - This class represents any other services that you want to implement on the server side. In this WCF client server example, this manager class implements only one method - GetServerTime(). But this method validates to see if user is authenticated before returning the server time.
ClientMessageInspector
This class implements the interface IClientMessageInspector and is used to inspect the messages from the client side. In our example, we are adding some custom headers to the request using this class. We are sending the authentication token as part of the header to the server. Server retrieves this token and validates the calls.
ServerMessageInspector
This class implements the interface IDispatchMessageInspector and is used on the server side to inspect the incoming requests.
CustomBehavior
CustomBehavior class implements the interface IEndpointBehavior and it is used to add the custom message inspectors to the WCF system.
How it works ?
The client application first shows the login screen. If user successfully login, an Authentication token is returned by the server. The client stores this token using a custom class called ClientContext. From this point onwards, the ClientmessageInspector class retrieves this token and sends to the server as a custom header along with each request.
On the server side, service methods explicitly checks if the authentication token is passed in the header and verifies it is valid or not.
References
The purpose of this article is to provide a simple client server sample application that uses WCF with net.tcp binding. I have not explained how to use custom behaviours to inspect the messages on the client and server side, even though I have used them here to inject the headers to the requests and responses.
I learned it from Paolo Pialorsi's blog:
Handling custom SOAP headers via WCF Behaviors
AttachmentsWCF_NET_TCP_Client_Server_Sample (19314-301840-WCF_SimpleClientServer_net_tcp.zip)
|
| Author: saji 18 Jul 2008 | Member Level: Gold Points : 1 |
hii... wht is its main differnce from remoting. is it same as remoting ?
|
| Author: beena 28 Jul 2008 | Member Level: Bronze Points : 0 |
Sharepoint-Webparts
SharePoint2003 Development - Building |
| Author: Nagarajan 30 Jul 2008 | Member Level: Gold Points : 0 |
Good One
|
| Author: Arun Kumar Pandey 07 Aug 2008 | Member Level: Silver Points : 1 |
WCF is not same as remoting.Remoting works only on Microsoft plateform. WCF is a unification technology which unites the following technologies:-
.NET remoting MSMQ Web services COM+.
|
| Author: avtar 18 Aug 2008 | Member Level: Gold Points : 2 |
WCF is more loosely coupled inshort in remoting your hosting that is low level protocol TCPIP and your logic are tightly coupled where as in WCF you write your logic once and host it as webservice , remote service ..etc
so if u see in earlier version if same logic u want to host as webservice over http and also as remote serive over tcpip , you have to re-write everything but in wcf its just write once and host it on any binding..
|