4

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

现在服务本身运行良好,但我怎样才能显示这样的操作: 在此处输入图像描述

感谢 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:)

4

1 回答 1

9

如果您有一个带有 SOAP 绑定的 WCF 服务,那么不幸的是,您很不幸:在 WCF 中没有办法在开箱即用的情况下获得类似于 ASMX 的所有服务的列表。

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

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

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

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

阅读所有关于它的内容:

于 2011-02-03T12:19:08.377 回答