大佬教程收集整理的这篇文章主要介绍了在web.config中配置wcf rest服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<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>
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>
行为名称可以是任何名称,但它将用于匹配您在步骤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>
以上是大佬教程为你收集整理的在web.config中配置wcf rest服务全部内容,希望文章能够帮你解决在web.config中配置wcf rest服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。