[英]Displaying WCF Web service operations
所以我創建了一個WCF服務應用程序並將其托管在IIS7上。 它目前有一些測試'helloworld'方法。 當我在瀏覽器中運行它時,我得到這個屏幕:
現在服務本身很好用,但是如何顯示這樣的操作:
感謝marc_s的鏈接: http : //www.dotnetcurry.com/ShowArticle.aspx? ID = 399我已經按照所以我的web配置現在設置如下:
<?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綁定的WCF服務,那么你不幸的是運氣不好:WCF無法開箱即可獲得與所有服務類似的ASMX列表。
使用REST綁定( webHttpBinding
)和.NET 4.0,您可以生成一個自動幫助頁面,其中列出了URI模板,支持的HTTP方法等等。 您還可以在一定程度上調整該頁面。
為了生成自動幫助頁面,您需要定義(和引用)端點行為:
<behaviors>
<endpointBehaviors>
<behavior name="HelpBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
然后從webHttpBinding
端點引用該行為,您就完成了。
閱讀所有關於它的內容:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.