Steps to consume a WCF service in Visual
Studio 2010
1. As
described in above page, you will need to run svcutil.exeutility
to generate the code files that will be later used in client consumer
application. The svcutil.exe utility is installed with the Windows SDK’s and can be found at
location – “c:\Program Files\Microsoft SDKs\Windows\vX.0A\bin”, where X can be
any latest installed SDK number. In my case the location is as –
“c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin”
“c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin”
2. Now
create a directory/folder to store the proxy files generated by svcutil
utility. Here I am creating a folder named “WcfFiles” in c:\ drive.
3. Open command prompt, goto c:\WcfFiles location
and try following command as given in below image –
Syntax : c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\Svcutil.exe your_webservice_url
Syntax : c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\Svcutil.exe your_webservice_url
4. The
successful command execution will end with following 2 files in WcfFiles folder.
i.
Service1.cs
ii.
Output.config
Now next step is to create a Client or consumer application.
Create a new console application –
Here, I am creating a console application
named as "MyFirstWcfWebServiceClientApp"
Goto Add service reference
Enter your WCF web service URL and click on Go button
to see a list of available services. All your available web methods(services)
will appear on the pane below. Give specific reference namespace. Here I am
giving reference namespace as "MyFirstWcfWebServiceReference".
Click on Ok button to finish the Add service reference wizard.
Now add your existing Service1.cs file to
the project. In step 3 , we have created this file using svcutil.exe utility
which is located at "C:\WcfFiles" location.
Add following code to the Program.cs file.
Now, open app.config file from Solution Explorer
Remove “MyFirstWcfWebServiceReference” and keep onlyIService1 in contract.
Save all files and hit F5 button to execute the client application.
|
WCF service - Client/Consumer output
|
Your WCF web service
consumer/client application is ready now.
In this article we learn to consume a wcf service in console application.
I hope you enjoyed the article. If you find this article helpful, then could you please share the article on your social media?
Related WCF articles ...
In this article we learn to consume a wcf service in console application.
I hope you enjoyed the article. If you find this article helpful, then could you please share the article on your social media?
Related WCF articles ...
No comments:
Post a Comment