Saturday, December 20, 2008

WCFService Library Simple Application

Microsoft.NET framework 3.0 had new features called WCFServiceLibrary template through this you can create the dll for your service.Mostly this will be best option of making business logic for WCF Services.

In this post,I am going to explain how to create the WCFService Libray,how to utilise them in WCFService and then consuming the services.

Step 1

Select the template name "WCFServiceLibrary" and choose the .NET framwork 3.0 as above.

Step 2

Here I just created the function name GetDataLength.This will returns the number of characters in the passing string.
Before I removed the by default text from the source file.

Step 3

An implementation of the function GetDataLength will be

Step 4

After completion of compile,you can see the dll file on your project stored location.
This will be the source for your WCF service.

Step 5

Now open second visual studio 2008 window,and choose the classing WCF Service,here you are going to use the just created WCFServiceLibrary as source.

Step 6

In your WCFService application use AddReference to include the WCFServiceLibrary's dll as below

Step 7

In your code behind,I created the WCFService method name GetDataFromLibrary,this will takes the string as parameter,and then its length will be processed by the WCFServiceLibrary and sent back to your WCFService.

Step -8
Code Implementation for the above method.

Step 9
After this run the application to create the .svc file for generating proxy class for your consumer application.

Step 10

Create the proxy class using svcutil.exe

Step 11
Add the proxy class into your website application in order to consume the WCFService that use the WCFServiceLibrary dll.And place the text box and button for checking the user input's length.

Step 12

You must copy have the endpoint details in your web.config file.Check the output.xml on your generated proxy class location.Pick the servicemodel tag and upto endof servicemodel tag as belows

On your Button click event,Just follow the same code snippet for getting the result from the WCFService.

The result I have got,