The code for hosting and running a WCF service enables to run the service that can be consumed by the WCF client application. This third step involves a sequence of programming commands which enable to run a basic Windows Communication Foundation service. It consists of the following steps to self-host and run a service:
1. creating a base address for the service.
2. creating an instance for self-hosting the service.
3. enabling the metadata behavior
4. opening the service host
In this tutorial we are continuing extending the console application created in the previous tutorial: Implementing Service Contract in WCF.
Self-Hosting and Running a WCF Service
1. Specify a base address for the WCF service using Uri class instance. The following Uri will open the port number 5000 to expose the service instance:
2. Next create the ServiceHost instance for self-hosting the WCF service over the specified base address:
3. Then add a service endpoint that enables to expose the service:
4. To enable the metadata information exchange functionality of a WCF service, you must import the System.ServiceModel.Descriptionnamespace at the top of the program.cs file:
5. You can use the following C# code inside the Main method of program.cs file to run the basic WCF service.
6. Press F5 to compile and run the service and try to browse the base address URL in the Internet Explorer. If it shows the web service information without any error, it means you have created a service successfully.
Continue to next tutorial: Creating a WCF Client using Service Model Metadata Utility Tool.
Responses
0 Respones to "Hosting and Running a Basic WCF Service"
Post a Comment