显示WCF Web服务操作

ing*_*.am 4 c# wcf iis-7 operations web-services

所以我创建了一个WCF服务应用程序并将其托管在IIS7上.它目前有一些测试'helloworld'方法.当我在浏览器中运行它时,我得到这个屏幕: 在此输入图像描述

现在服务本身很好用,但是如何显示这样的操作: 在此输入图像描述

感谢marc_s的链接:http://www.dotnetcurry.com/ShowArticle.aspx? ID = 399 我已经按照所以我的web配置现在设置如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfServer.Service1">
        <endpoint address="" binding="webHttpBinding" contract="WcfServer.IService1" behaviorConfiguration="HelpBehaviour" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <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="AjaxBehavior">
          <enableWebScript />
        </behavior>
        <behavior name="HelpBehaviour">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension" />
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是,这只适用于本地.当我在IIS7上发布到我的服务器时,单击帮助链接时出现404错误页面.有谁知道为什么会这样,或者之前遇到过它?

(最后1位是通过运行解决:aspnet_regiis.exe -iru)

mar*_*c_s 9

如果你有一个带有SOAP绑定的WCF服务,那么你不幸的是运气不好:WCF无法开箱即可获得与所有服务类似的ASMX列表.

使用REST绑定(webHttpBinding)和.NET 4.0,您可以生成一个自动帮助页面,其中列出了URI模板,支持的HTTP方法等等.您还可以在一定程度上调整该页面.

为了生成自动帮助页面,您需要定义(和引用)端点行为:

<behaviors>
   <endpointBehaviors>
       <behavior name="HelpBehavior">
           <webHttp helpEnabled="true" />
       </behavior>
   </endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

然后从您的webHttpBinding端点引用该行为,您就完成了.

阅读所有关于它的内容:

  • +1我只是写了相同的答案.我只想添加REST服务的帮助页面URL有sufix/help:http://msdn.microsoft.com/en-us/library/ee230442.aspx (2认同)