Here’s a quick step through of using WCF in Visual Studio 2005. In this case I used a local machine, running Windows 2003, for the service and the client.
There’s lot of possible paths, and this is just one path through. I focused on “Hello World” to run through the basic mechanics, but chose a path to touch enough things that might be interesting to explore another day.
Use Visual Studio 2005 to do a dry run of creating a WCF service hosted in IIS and calling it from a console application on your local development workstation. (Note that you don’t need to host WCF in IIS; for example, you could use a surrogate console application.)
Summary of Steps
- Step 1. Create the test service
- Step 2. Add a Hello World Method
- Step 3. Test your WCF service
- Step 4. Enable meta-data for your WCF Service.
- Step 5. Create the test client.
- Step 6. Add a Web Services reference to your WCF Service.
- Step 7. Add the namespace to your
- Step 8. Call your WCF service
Step 1. Create the test service
In this step, we’ll create a WCF service that uses HTTP bindings, for backward compatibility (non-.NET 3.0 clients)
- In Visual Studio, click File -> New Web Site
- Select WCF Service
- Browse to a directory to store your project: (e.g. D:\Dev\WCF\Test1\Serve )
- Enable wsHttpBinding. To do so, right-click Web.config and click Edit WCF Configuration … Expand Services > expand MyService -> expand Endpoints. Click (Empty Name). Change wsHttpBinding to basicHttpBinding
- Create the virtual directory. In your File Manager, right-click your Server folder (i.e. D:\Dev\WCF\Test3\Server) and click Properties, then Web Sharing, and click Share this folder, then click OK.
Step 2. Add a Hello World Method
In Service.cs, you’ll add your Hello World method:
- Add the HelloWorld operation contract below public interface: [ServiceContract()]
public interface IMyService
string MyOperation1(string myValue1);
string MyOperation2(DataContract1 dataContractValue);
- Add your HelloWorld method below public class MyService : public class MyService : IMyService
public string MyOperation1(string myValue1)
return “Hello: ” + myValue1;
public string MyOperation2(DataContract1 dataContractValue)
return “Hello: ” + dataContractValue.FirstName;
public string HelloWorld()
return “Hello World”;
Compile and debug any errors.
Step 3. Test your WCF service
- In IIS Manager, under Default Web Site, right-click expand Server (the virtual directory you just created)
- Right-click Service.svc and click Browse.
There’s two issues you might hit here:
- You don’t have ASP.NET installed/enabled. To fix this, first run aspnet_regiis /i from your .NET installation directory (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) Then, allow ASP.NET in your IIS Manager. To do so, in IIS Manager, expand Web Service Extensions, select ASP.NET v.2.0.50727 and click Allow.
- You might see “Security settings for this service require ‘Anonymous’ Authentication but it is not enabled for the IIS application that hosts this service.” To fix this, first enable anonymous access. In IIS Manager, right click your v-dir (Server), click Properties, click Directory Security, click Edit under Authentication and Access control, click Enable Anonymous Access, then OK your way out of the dialogues. Next, recycle IIS. In a command prompt, type IISreset. If successful, when you browse your Service.svc file from IIS Manager (e.g. http://localhost/service/service.svc). you’ll get a message that starts with the following:
This is a Windows© Communication Foundation service.
Metadata publishing for this service is currently disabled.
Step 4. Enable meta-data for your WCF Service.
- In VSTS, right-click Web.config and click Edit WCF Configuration. In WCF Configuration, expand Advanced, then expand Service Behaviors, then
right-click returnFaults and click Add Service Behavior Element Extension. Select serviceMetadata and click Add.
- In WCF configuration, select serviceMetadata and change HttpGetEnabled to True. Close the dialogue and save changes.
- Test your service again. Browse to http://localhost/Server/Service.svc and this time you should see your service (e.g. MyService Service). You
will see a message that starts with the following:
“You have created a service.”
Step 5. Create the test client.
In this step, we’ll create a quick console app to call the WCF service:
- In Visual Studio, click File -> New -> Project
- Select Console Application.
- Browse to a directory to store your test client: (e.g. D:\Dev\WCF\Test1\WCFClient)
Step 6. Add a Web Services reference to your WCF Service.
In this step, we’ll add a Web Services reference.
- Right-click References
- Click Add Web Reference …
- In the Add Web Reference dialogue, add the path to your WCF Service (http://localhost/Server/Service.svc)
- Click Add Reference to close the dialogue. You should then see your Web Service reference show up under Web References.
Step 7. Add the namespace to your
- Browse to your Reference.cs file. You’ll find the file below Reference.map under your Web service reference. You might need to click the Show All Files button on the Solution Explorer so you can see the files under your Web service reference.
- Find the namespace. You’ll see a line similar to the following:
- Add the using statement to your Program.cs file.
Step 8. Call your WCF service
In your test client, call your WCF service:
static void Main(string args)
MyService service = new MyService();
foo = service.HelloWorld();
When you compile and run your console application, you should see the following:
Press any key to continue . . .
Hopefully this step through helps you quickly see some of the bits and pieces you can play with.