显示WCF Web服务操作

时间:2011-02-03 12:11:56

标签: c# wcf web-services iis-7 operations

所以我创建了一个WCF服务应用程序并将其托管在IIS7上。它目前有一些测试'helloworld'方法。当我在浏览器中运行它时,我得到这个屏幕: enter image description here

现在服务本身效果很好,但是如何显示这样的操作: enter image description here

感谢marc_s提供的链接:http://www.dotnetcurry.com/ShowArticle.aspx?ID=399我已经关注了,所以我的网络配置现在设置为:

<?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>

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

(最后一位通过运行:aspnet_regiis.exe -iru

解决

1 个答案:

答案 0 :(得分:9)

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

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

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

<behaviors>
   <endpointBehaviors>
       <behavior name="HelpBehavior">
           <webHttp helpEnabled="true" />
       </behavior>
   </endpointBehaviors>
</behaviors>

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

阅读所有相关内容: