Mark sheet maintenance using WCF

Before I start with this article I’d like you to know certain things about WCF or the Windows Communication Foundation. We all have heard about servers and applications running at server end(the back end) like, a Java Servlet. The basic idea in the infrastructure is that certain parts of the applications are deployed as services across the hosts, which means, the application is not running in a native machine but as a service across several machines connected and sharing stuff between themselves through a network.

It is a system for creating connections between applications using services and endpoints. WCF is, more than anything, an infrastructure technology for messages. Just as roads support cars, and as electricity travels over wires and cables, and as pipes convey water, WCF exists to transfer messages between any two endpoints. And it does so securely as well. That is, you can create messages that are encrypted to keep your information safe from being tampered with. A standard example will be Data integration service for any Windows Forms Application that you develop or a WPF one, even a Silverlight based RIA (Rich Internet Application).

So, before we start, let’s get the basics clear :

  • We have a DataContract where we add Data members.
  • We have a ServiceContract where we mention about operations to be performed on the data, i.e, we declare methods.
  • Finally, we have ServiceBehaviour where we assign how the service needs to be executed or how our WCF application should behave.

So, getting this correct we shall move on to our project.

  1. First create a WCF Service Library in Visual Studio :

Image2. Add a Data.cs class to the project and enter the following code :

Screenshot - 2_24_2013 , 8_30_24 PM

3.  Now add another class to the project named IDataService.cs, change it to an interface(instead of a class), and enter the code:

Screenshot - 2_24_2013 , 8_35_17 PM

4.  Now add another class named as DataService.cs and add the following code :

Screenshot - 2_24_2013 , 8_38_30 PM

5. Now build the project.

6.   Now that our model is ready we need to make certain changes to the App.Config file so that our application works as we need in the host.

First, we edit WCF configuration of app.config file by right clicking, check the service tab, and we have a browse window go to e:\programming\c#\marksheet\marksheet\bin\Debug (or project location) and choose the appropriate service dll.

Screenshot - 2_24_2013 , 8_46_02 PM

 

Now, let’s select some end points by choosing empty endpoint name and in service endpoint window select contract browse to appropriate service like above.

Screenshot - 2_24_2013 , 8_48_22 PM

 

Now, close, save all if prompted and deploy (Ctrl+F5).

Screenshot - 2_24_2013 , 8_49_46 PM

 

Now there you have your methods, lets deploy the Submit_Data() method to add an entry to our Database and then invoke :

Screenshot - 2_24_2013 , 8_51_28 PM

 

Continue, for other methods, and that’s it. Simple and easy.

 

Advertisements

One thought on “Mark sheet maintenance using WCF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s