2011-02-03 81 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端點引用的行爲,就大功告成了。

閱讀所有關於它: