Objective
This article will give step by step walkthrough
1. How to create a basic WCF 4.0 Service?
2. How to host WCF Service in IIS 7.5?
3. Hot to test service in a client.
Create WCF Service
Create WCF service. Open visual studio select new project and then from WCF tab select WCF Service application to create a new WCF service.
Delete the default code created by WCF from IService1 and Service1.svc.cs
a. So delete the data contract
b. Modify the service contract as below. Just make one operation contract to return a string .
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService5
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetMessage();
}
}
Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService5
{
public class Service1 : IService1
{
public string GetMessage()
{
return "Hello From WCF Service ";
}
}
}
Leave the default configuration created by WCF.
Web.Config
<?xmlversion="1.0"?>
<configuration>
<system.web>
<compilationdebug="true"targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadatahttpGetEnabled="true"/>
<serviceDebugincludeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironmentmultipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modulesrunAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Host WCF Service in IIS 4.0
Open IIS
a. Open the command prompt in administrator mode. To do click on Start button then type RUN in search and then in Run window type inetmgr to open IIS .
输入 命令 : inetmgr
b. Right click on Sites and then click Add Web Site

Now a window will open.
detail refer from following link
http://debugmode.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/
posted on
浙公网安备 33010602011771号