在web.config中配置wcf rest服务

在web.config中配置wcf rest服务,第1张

概述在web.config中,以下代码块应该用于WCF RESTful服务吗? <endpoint address="" binding="webHttpBinding"contract="Wcf_Test.IMyService" behaviorConfiguration="httpEndpointBehavour"> <identity> <dns value= 在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>

服务名称为[项目名称].[服务名称]
行为配置将与您在下一步中声明的行为相同
绑定必须是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服务所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1130656.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存