转(详见):http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1bad2198-65cb-445d-84cb-1fae17828eef
分以下几步骤:
1、VS2008创建WCF服务项目
2、配置服务接口UriTemplate
[OperationContract]
[WebGet(UriTemplate = "/Tests/{sValue}", ResponseFormat = WebMessageFormat.Json)]
string GetData(string sValue);
3、配置WebConfig,例:
<system.serviceModel>
<services>
<service behaviorConfiguration="BA.Services.SiteGetNewsServiceBehavior" name="BA.Services.SiteGetNewsService">
<endpoint address="" behaviorConfiguration="WebHttp" binding="webHttpBinding"
bindingConfiguration="" contract="BA.Services.ISiteGetNewsService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BA.Services.SiteGetNewsServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
4、配置*.svc服务标记:
<%@ ServiceHost Language="C#" Debug="true" Service="Rest4Func.Service1" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
5、测试服务:http://***/Service1.svc/tests/定义参数,弹出一个文件保存
6、实例(项目中以Service1.svc为例):/Files/lmjob/WcfRest.rar
附:.Net2.0创建Rest服务代码:
/Files/lmjob/RESTService.zip