如何在WCF中创建Restful API?

时间:2018-08-21 04:27:22

标签: wcf asp.net-web-api

在WEB API中,RESTful API是使用ADO.NET创建的,而WCF呢?

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

1 个答案:

答案 0 :(得分:0)

不仅如此。
我们还需要使用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