2011-02-03 110 views
4

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

现在服务本身的伟大工程,但我怎么能显示的操作是这样的: 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

+0

你是最好的使用WCFTestClient在C测试WCF:\程序文件(x86)\微软的Visual Studio 10.0 \ Common7 \ IDE(适用于VS 2010) – 2011-02-03 12:14:20

+0

这是我做的第一件事:哪些工作正常! – 2011-02-03 12:24:54

回答

9

如果你有一个SOAP绑定一个WCF服务,你是不幸的运气了:有没有办法在WCF开箱即获得上市类似于所有服务的ASMX。

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

为了有产生的自动帮助页面,您需要定义(和参考)的终结点行为:

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

然后从你的webHttpBinding端点引用的行为,就大功告成了。

阅读所有关于它: