First WCF Service Application

In this blog, I will be creating a WCF service application project. If you want to read WCF from the beginning, please read my earlier blog.

Let's create first WCF Service Application

To create a WCF project open Visual Studio 2012 and select File->New Project.
Click on WCF from installed template (Left area)

wcf service application

In above screen, you can see 4 types of WCF project can be created. But there is confusion between WCF Service Library and WCF Service Application.
You may find the difference between these 2.

WCF Service Library:
A project for creating a host-independent WCF service class library (.dll).

WCF Service Application:
A project for creating WCF service application that is hosted in IIS/WAS.  Once you choose WCF service application, an svc file automatically added to your project solution but not in WCF service library.

So let’s start our first program in WCF by choosing WCF service application as I will be creating IIS hosted service.
Once you create this project, your solution will look like this:



How to test WCF service
To test WCF service you may use WCFTESTCLIENT.
To use this client, open Visual Studio command prompt, and type wcftestclient

wcf service application
Below window will open.
wcf service application

Right click on “My Service Project” and select Add service, below box will appear. Type your service URL and press ok.

wcf service application

wcf service application

To test your operation click on the name of operation from left side area.
Then provide input/parameters in right side area and click on Invoke to see the output.

wcf service application



Generating proxy class
SVCUTIL.EXE: As per Microsoft statement, SVCUTIL is a Service Model Metadata Utility Tool. It is used to generate the proxy class.
Basic syntax to generate proxy class using SVCUTIL is
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:59314/Service1.svc
To run above command you need Visual Studio Command Prompt.

wcf service application svcutil

Once you generate the proxy and config files, you may check these files at given location.
App.config will look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:59314/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>


And Proxy class will expose all variables operations which were mentioned in WCF application.

In next blog, I will write about proxy class and how to use them.

Protected by Copyscape

Comments

  1. Thank you for posting wcf related content.
    Much appreciated.

    ReplyDelete
  2. WCF content posted is very helpful for freshers.
    Post more for a developer having more than 3 yrs. of exp.

    ReplyDelete

Post a Comment

Dear Readers, Please post your valuable feedback in the comment section if you like this blog or if you have any suggestions. I would love to hear the same from you. Thanks

Popular

SharePoint Interview Questions and Answers

Calling ASP.Net WebMethod using jQuery AJAX

What is Cloud Computing - A guide for beginners