c# - 显示 WCF Web 服务操作

标签 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)

最佳答案

如果您有一个带有 SOAP 绑定(bind)的 WCF 服务,那么不幸的是您运气不好:在 WCF 中没有开箱即用的方法来获得类似于 ASMX 的包含所有服务的列表。

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

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

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

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

阅读全部内容:

关于c# - 显示 WCF Web 服务操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4885983/

相关文章:

javax.ws.rs.core.Response.readEntity() 陷入无限循环

web-services - SharePoint:GetListItemChangesSinceToken 与 GetListItemChangesWithKnowledge?

c# - 如何在.NET应用程序中正确检查与mysql的数据库连接?

c# - Wcf 服务客户端不接收流消息

c# - WCF - 是否可以使用 HttpListener 或套接字监听 WCF ChannelFactory

java - 如何从基于 java 的服务获取声音

c# - Entity Framework和MVC在业务层或数据访问层创建DbContext

c# - 无法从 C# 应用程序调用 Clojure clr 静态方法

c# - 如何将 List<Anonymous Type> 转换为 List<string>

c# - WCF 为 IIS 注册依赖项