【问题标题】:Displaying WCF Web service operations显示 WCF Web 服务操作
【发布时间】:2011-02-03 12:11:56
【问题描述】:

所以我创建了一个 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

【问题讨论】:

  • 您最好使用 WCFTestClient 在 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE (for VS 2010) 中测试 WCF
  • 这是我做的第一件事:效果很好!

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


【解决方案1】:

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

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

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

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

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

阅读所有相关信息:

【讨论】:

  • +1 我只是在写同样的答案。我只会添加 REST 服务的帮助页面 URL 有后缀 /help :msdn.microsoft.com/en-us/library/ee230442.aspx
  • 如何获取自动生成的帮助页面?我正在使用 .NET 4.0 并尝试提供 REST 服务,但 web.config 没有定义任何端点。我必须自己写这些吗?
  • @ing0:是的,如果您根本没有定义端点,WCF 4 将根据您定义的基地址和服务合同启动一些默认端点。只要你定义了一个端点,那么就只使用你的那个端点
  • 好的,谢谢,我需要编写一个端点,然后我也参考我的帮助行为。
  • 感谢您提供我需要的信息 marc!
猜你喜欢
  • 1970-01-01
  • 2012-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多