为了配置一个WCF REST服务,你需要在你的web.config文件中的几件事情
1)声明您的服务和其端点
<services>
<service name="SparqlService.SparqlService" behaviorConfiguration="ServiceBehavior">
<endpoint binding="webHttpBinding" contract="SparqlService.ISparqlService"
behaviorConfiguration="webHttp"/>
</service>
</services>
服务名称为[项目名称]。[服务名称] 行为的配置将是相同的名称为您在下一步 申报行为绑定必须的WebHttpBinding,因为你希望它是REST。如果你想SOAP,您声明为basicHttpBinding的 合同是[项目名称]。[接口名称]在端点 行为的配置将是您在下一步
2)声明服务行为申报的名称(通常是默认)
<behavior name="ServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
行为名称可以是任何东西,但它会被用来匹配BehaviorConfiguration您在步骤1中声明保留 仅剩下
3)声明你的终结点行为
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
行为名称可以是任何内容,但它将用于匹配端点中的behaviorConfiguration。
最后,这是在web.config应该是什么样子的一个简单的REST服务:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="SparqlService.SparqlService" behaviorConfiguration="ServiceBehavior">
<endpoint binding="webHttpBinding" contract="SparqlService.ISparqlService"
behaviorConfiguration="webHttp"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
使用WCF SVC配置编辑器中的其余类型。 – avi