How to Host a WCF Service in IIS
If you are new to WCF services then please read my earlier blogs. Go through with this link - WCF Tutorial step by step.
WCF supports a various way to host a service. In this blog, I will explain about Hosting a WCF Service in IIS.
Step 1: Create a WCF Library project in Visual Studio.
Step 2: Delete Class and Interface which is created by default.
Step 3: Create an interface IProduct. Add one operation contract in this.
Step 5: Right click on Solution in Visual Studio. Add a new website in the same solution. Select WCF Service.
Step 6: Delete files from App_Code. Add the reference of the WCF service project.
Step 7: Open .SVC file and remove code behind. .SVC file should look like this.
Step 15: Once Service Reference added. You write code to consume WCF service that you created.
WCFServiceReference is the name which I gave while adding WCF service reference.
Step 16: Your output will.
1001 is the Product Id which was passed from the client.
WCF supports a various way to host a service. In this blog, I will explain about Hosting a WCF Service in IIS.
How to host WCF service in IIS?
Step 1: Create a WCF Library project in Visual Studio.
Step 2: Delete Class and Interface which is created by default.
Step 3: Create an interface IProduct. Add one operation contract in this.
[ServiceContract]
interface IProduct
{
[OperationContract]
string GetProduct(int productId);
}
Step 4: Add a class Product.cs to implement this interface.
class Product: IProduct
{
public string GetProduct(int productId)
{
return "Product Id - " + productId + "is available at store";
}
}
Step 5: Right click on Solution in Visual Studio. Add a new website in the same solution. Select WCF Service.
Step 6: Delete files from App_Code. Add the reference of the WCF service project.
Step 7: Open .SVC file and remove code behind. .SVC file should look like this.
<%@ ServiceHost Language="C#" Service="WcfServiceLibraryMaster.Product" %>
Step 8: Now host your WCF service in IIS. Open IIS. Right click on Default web site and add an application. You may also create an independent site in IIS.
Step 9: Fill all the details.
Step 10: Once done. Right click on newly added Application or Website and select Switch to content view. You can see your service file there.
Step 11: Browse your file and you will see an output like this.
Step 12: Now it's time to consume the WCF service.
Step 13: Add a new Website in the same solution. Create ASP.Net website.
Step 14: Add service reference in this website.(Browse the .svc file in IIS and copy the URL, right click on Website and add Service Reference.)
Step 15: Once Service Reference added. You write code to consume WCF service that you created.
WCFServiceReference is the name which I gave while adding WCF service reference.
WCFServiceReference.ProductClient objClient = new WCFServiceReference.ProductClient();
string ss = objClient.GetProduct(1001);
Response.Write(ss);
1001 is the Product Id which was passed from the client.
Product Id - 1001 is available at store
Related blogs to WCF Service-
Related blogs to WCF Service-
- Introduction to WCF
- ABC of WCF
- Basics of WCF Architecture
- WCF vs Web Service
- What is XML serialization?
- WCF Binding
- Create first WCF application
- Fault Contract in
- WCF Data Contract vs Message Contract
- Message Contract
- Data Contract Serialization and De-Serialization
- Data Contract in WCF
- Operation Contract in WCF
- Service Contract in WCF
- How to host a WCF service in IIS?
- WAS Hosting in WCF
- Self Hosting in WCF
- How to create WCF RESTful Service.
Comments
Post a Comment
Dear Readers, Please post your valuable feedback in the comment section if you like this blog or if you have any suggestions. I would love to hear the same from you. Thanks