所以我创建了一个 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
)
最佳答案
如果您有一个带有 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/