Configure the Development Environment
- Install Microsoft Visual C# 2010 Express
- Install Microsoft Visual Web Developer 2010 Express installed (you can download all Express editions on one iso image at http://www.microsoft.com/express/Downloads/#2010-All)
- Enable Windows features:
- IIS Metabase and IIS 6 configuration compatibility
- IIS Management Console
- ASP.NET
- In IIS Manager, under Application Pools right click DefaultAppPool, select Basic Settings then change .NET framework version to v4.0.x
- Install Windows SDK. This can be downloaded from http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en
Create the Web Service
- First we will create the web service. To do this we need to run Visual Web Developer 2010 Express with administrator privileges so hit the start button type in “web dev” or similar and when Web Developer is highlighted press ctrl+shift+enter. This will start it as an administrator and show the UAC prompt. Alternatively locate Web Developer in the start menu then right click and select run as administrator.
- Select File –> New web site and choose WCF Service and name it MultiplyService
- Add code App_Code / IService.cs
- Add code to App_Code / Service.cs
- Run the service by pressing ctrl F5 and click the Service.svc link in the page that opens. Nothing much to see here yet, you need a client to view this data. As indicated on the page you need to run the svcutil.exe utility to generate code that will be used by the client application
The svcutil.exe utility is installed with the Windows SDK and can be found at c:\Program Files\Microsoft SDKs\Windows\v6.0a\bin
To create the Service.cs file on the desktop try the following in a cmd prompt:
- That ends the WCF service. Leave all of this running, including the internet explorer window that Web Developer opened and open Visual C# Express to start on the client application.
Create the Client Application
- Start up Visual C# 2010 Express and select File –> New Project. Select WPF Application and name it MultiplyClient.
- Add a Service Reference
In the Service Reference dialog paste in the address from the internet explorer window that web developer opened. Select the service and select OK
- Copy the Service.cs file on the desktop that was generated by svcutil into the root folder of the project
- Add two entry textboxes, a multiply button and a result textbox to the MainWindow.xaml
- Add code to MainWindow.xaml.cs to call the service when the multiply button is clicked
- Modify the app.config file. Simply change the contract value from “ServiceReference1.IService” to “IService”
- Press ctrl+F5 to run the WPF application. Enter two values to multiply and hit the Multiply button, you should see the answer in the result textbox!
References
- The basic gist of WCF services:
http://www.xvpj.net/2008/03/08/wcf-step-by-step-tutorial/ - Adding IIS features:
http://www.howtogeek.com/howto/windows-vista/how-to-install-iis-on-windows-vista/ - Where to find the svcutil.exe utility:
http://www.dotnetspider.com/forum/239950-Where-find-svcutil-exe.aspx
2 comments:
This post is very interesting and useful to learn how to create and consume wcf service for beginners.
Sure looks as though you ripped this off from Mr Ben Caldwell's blog: http://carvingcode.blogspot.com/2010/04/creating-wcf-web-service-with-vs2010.html
Post a Comment