【问题标题】:How to create Restful API's in WCF?如何在 WCF 中创建 Restful API?
【发布时间】:2018-08-21 04:27:21
【问题描述】:

在 WEB API 中,Restful API 是使用 ADO.NET 创建的,WCF 怎么样?

如果我们在 WCF 中装饰WebInvoke(method="POST",ResponseFormat=WebMessageFormat.Json) 和API结构一样吗?

【问题讨论】:

标签: wcf asp.net-web-api


【解决方案1】:

不仅如此。
我们还需要使用 webhttpbinding 或 webservicehost 来托管服务。 这里是 web.config(wcf 服务应用)

    <services>
  <service name="WcfService1.Service1" behaviorConfiguration="mybehavior">
    <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev"></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mybehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webbev">
      <webHttp/>
    </behavior>
  </endpointBehaviors>

您可以参考以下文档的示例加深您的理解。没有比这更好的了。
Here is official document

【讨论】:

    猜你喜欢
    • 2012-09-25
    • 1970-01-01
    • 2011-08-12
    • 2015-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2012-01-11
    相关资源
    最近更新 更多