在web.config中配置wcf rest服务
发布时间:2020-12-14 23:42:42 所属栏目:资源 来源:网络整理
导读:在web.config中,以下代码块应该用于WCF RESTful服务吗? endpoint address="" binding="webHttpBinding"contract="Wcf_Test.IMyService" behaviorConfiguration="httpEndpointBehavour" identity dns value="localhost"/ Identity /endpoint 和 behaviors se
在web.config中,以下代码块应该用于WCF RESTful服务吗?
<endpoint address="" binding="webHttpBinding"contract="Wcf_Test.IMyService" behaviorConfiguration="httpEndpointBehavour"> <identity> <dns value="localhost"/> <Identity> </endpoint> 和 <behaviors> <serviceBehaviors> <behavior name="httpBehaviour"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False"/> </behavior> </serviceBehaviors> 和 <endpointBehaviors> <behavior name="httpEndpointBehavour"> <webHttp /> </behavior> </endpointBehaviors> </behaviors> 解决方法
要配置WCF REST服务,您需要在web.config文件中执行一些操作
1)声明您的服务及其端点 <services> <service name="SparqlService.SparqlService" behaviorConfiguration="ServiceBehavior"> <endpoint binding="webHttpBinding" contract="SparqlService.ISparqlService" behaviorConfiguration="webHttp"/> </service> </services> 服务名称为[项目名称].[服务名称] 2)声明服务行为(通常是默认) <behavior name="ServiceBehavior" > <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> 行为名称可以是任何名称,但它将用于匹配您在步骤1中声明的BehaviorConfiguration 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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |