2015-05-28 66 views
0

我有一個WCF REST服務與WCF服務的應用程序所承載的下列合同:爲什麼我的WCF幫助頁面只顯示GET方法?

[ServiceContract] 
public interface IService 
{ 
    [OperationContract] 
    [WebInvoke(Method="GET", 
     RequestFormat=WebMessageFormat.Json, 
     ResponseFormat=WebMessageFormat.Json, 
     UriTemplate="key/{key}")] 
    Task<string> GetDocumentInDefaultBucket(string key); 

    [OperationContract] 
    [WebInvoke(Method = "GET", 
     RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, 
     UriTemplate = "bucket/{bucket}/key/{key}")] 
    Task<string> GetDocument(string bucket, string key); 

    [OperationContract] 
    [WebInvoke(Method = "POST", 
     RequestFormat = WebMessageFormat.Json, 
     BodyStyle= WebMessageBodyStyle.Wrapped, 
     UriTemplate = "doc")] 
    Task<bool> InsertDocumentInDefaultBucket(string doc); 

    [OperationContract] 
    [WebInvoke(Method = "PUT", 
     RequestFormat = WebMessageFormat.Json, 
     BodyStyle = WebMessageBodyStyle.Wrapped, 
     UriTemplate = "udoc")] 
    Task<bool> UpdateDocumentInDefaultBucket(string doc); 
} 

然而,顯示在WCF幫助頁只有GET方法:

WCF Help Page

我在配置文件中沒有明確定義的服務,我剛將以下代碼添加到application_start事件中:

RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(Service))); 

任何幫助表示讚賞。

更新1:同樣的項目就像其他類似的開發環境中的魅力。

UPDATE 2:OMG!它適用於IIS WCF Help Page

回答

0

在Web.config文件中添加System.Web.Routing.UrlRoutingModule模塊並將runAllManagedModulesForAllRequests屬性設置爲true。還要將UrlRoutingHandler處理程序添加到元素,如下所示。

<system.webServer> 
<modules runAllManagedModulesForAllRequests="true"> 
    <add name="UrlRoutingModule" 
    type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
</modules> 
<handlers> 
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/> 
</handlers> 

0

你已經混幾件事情。這是關於WebGet和WebInvoke的快速信息。 WebGet代表HttpGet操作。 WebInvoke代表郵政申請E.g. HTTP PUTHTTP DELETEHTTP POST操作。

您只對這兩種Operations.Try類型使用WebInvoke,糾正這些屬性並查看是否有效。接下來,您在Post方法中缺少ResponseFormat attribute。如果您的配置僅支持Json和默認格式化程序(在這種情況下,它可能是XmlFormatter),可能會抑制它顯示在幫助頁面上。

如果這不起作用,請在源代碼中添加您的端點配置和其他任何自定義配置。

+0

我決定在我的兩個同事機器上測試同一個項目,它在兩種情況下都像一個魅力!這個問題似乎與我的環境無關。 –

0

嗯,我很困惑...

命中CRTL + F5在Internet Explorer和它的作品。導航器在其緩存中保留了舊版本。

相關問題