Host And Use A WCF Service From A Client - WCF Part 2




First of all for creating WCF Service in Visual Studio, please follow below link How To Create A WCF Servcie In Visual Studio In order to consume this WCF Service, we needs to Host in IIS. And then we will call this Hosted WCF Service on the client Application. WCF Services are absolutely platform independent. We can call this in any language. Hosting a WCF Service on IIS is similar to Hosting a Website on IIS. You can find the content about Hosting a Web App On IIS in the following link. Hosting A WCF Service On IIS From Visual Studio




After hosting the WCF Service, its time to Consume the Service in an Appliaction.

1. Copy the Hosted WCf Service URL from IIS.

2. Then Right Click on the Client Project and click on the Add Service Reference link.

Host And Use A WCF Service In Visual Studio, Host And Consume A WCF Service, Use A WCF Service, Host And Consume Service In Asp.Net, Host And Use A WCF Service In Asp.Net MVC, WCF Service In Asp.Net MVC, Asp.Net, WCF, REST, MVC

On the newly opened window provide the WCF Service Address and click Go Button. This will fetch and list the Services and Operations from IIS automatically. Provide a suitable name under Namespace for the Service Reference as in the above image. Now click the OK Button for adding the WCF Service to the Solution as shown below.

Host And Use A WCF Service In Visual Studio, Host And Consume A WCF Service, Use A WCF Service, Host And Consume Service In Asp.Net, Host And Use A WCF Service In Asp.Net MVC, WCF Service In Asp.Net MVC, Asp.Net, WCF, REST, MVC

After adding the WCf Service, now we can call the service on code as shown below.

Host And Use A WCF Service In Visual Studio, Host And Consume A WCF Service, Use A WCF Service, Host And Consume Service In Asp.Net, Host And Use A WCF Service In Asp.Net MVC, WCF Service In Asp.Net MVC, Asp.Net, WCF, REST, MVC

Create an Instance of the Service Reference and Invoke the Preferred Method. Created Instance would list all the methods in the WCF Service. In the above example, we have called the GetData method which returns a string value. By this way we can call a WCF service in a Client Application.