2015-05-28 67 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和它的作品。导航器在其缓存中保留了旧版本。

相关问题