Create WCF Web Service in Visual Studio

Leave a comment

Windows Communication Foundation (WCF) web services can be created in Visual Studio. Note these web services replace the old asmx web services.

To create a web service in Visual Studio do the following.

Create a new project in Visual Studio and select WCF Service Application:

This creates the solution:

Delete the existing Service1.svc and IService1.cs and add a new WCF Service:

This will create these 2 files again. Note the file contains the ServiceContract and the OperationContract:

The DoWork method is created as a shell:

We will implement a Hello World web service. Change DoWork() to return a string “Hello World”:

Press F5 and Invoke. The string Hello World is returned:

To test consuming and invoking this through code, let’s create a new console app and add it to the solution:

Select Add Service Reference:

Click Discover to pick up the service created:

Add the following code. Add a using statement for the web service, and create an instance of ServiceClient. Display the Hello World output in the console.

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

Leave a Reply

Your email address will not be published. Required fields are marked *