Wednesday, 11 January 2012

C#.Net How To: Test a WCF Service in VS 2010 using wcftestclient.

I am assuming that your WCF web service is already built and ready to test. Please refer my previous post on how to Create a WCF Web Service in Visual Studio 2010
 
Before proceeding with wcftestclient utility, you must know the URL of your WCF web service. Execute the web service you created and then you will get your WCF web service URL from following screen –
 
Wcf service interface
WCF Web Service - WCF Web Service Interface
 
1)   Once you get WCF service URL. Start a visual studio command prompt. In windows 7 OS, to start Visual Studio command prompt goto Start -> All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt (2010)

You will get following command prompt.

VS2010 command prompt
WCF Web Service - Visual Studio 2010 Command Prompt.
 2)   Type wcftestclient and hit enter/return key.

Visual Studio command prompt
WCF Web Service - Visual Studio 2010 Command Prompt.

3)   A WcfTestClient user interface will open in another windows.

WCfTestClient User Interface
WCF Web Service - WCfTestClient User Interface.

4)   Goto File -> Add Service.. menu.
WCF WCfTestClient User Interface
WCF Web Service - WCfTestClient User Interface.

5)   Type your WCF web service URL in the Add Service dialog box and click OK button.
WCfTestClient Add service
WCF Web Service - WCfTestClient Add service User Interface.

6)   After some processing you will get following WCF Test Client user interface.
All your web methods will appear on the left pane under My Service Projects.
WcfTestClient - Web Methods
WCF Web Service - WcfTestClient - Web Methods.

7)   Double click on any of the web method. In our case, double clicking on “WelComeMessage” web method will display request and response interface on right pane.
WCfTestClient Request
WCF Web Service - WCfTestClient - Request.

8)   Double Click on value field(null) and type your name. I am giving here value as “Brad Pitt” for name variable.
WCfTestClient Response
WCF Web Service - WCfTestClient -Response.

Now click on “Invoke” button. And check the response, it will show you the response from your web method.

9)   Similarly double click on other web methods on the left pane. The corresponding request and response interface will open in right pane. 


Sharing is Caring »»

2 comments:

Follow C# Tutorials