为什么我的WCF帮助页面只显示GET方法?

时间:2015-05-28 12:23:11

标签: c# wcf rest iis

我有一个WCF REST服务,在WCF服务应用程序中托管了以下合同:

[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);
}

但是,只有GET方法显示在WCF帮助页面中:

WCF Help Page

我没有在配置文件中明确定义服务,我刚刚将以下代码添加到application_start事件中:

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

任何帮助表示感谢。

更新1 :同一个项目就像其他类似开发环境中的魅力一样。

更新2 :天啊!它适用于IIS WCF Help Page

3 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

你混合了几件事。这是关于WebGet和WebInvoke的快速信息。 WebGet代表HttpGet操作。 WebInvoke代表帖子请求例如。 HTTP PUTHTTP DELETEHTTP POST次操作。

您只对两种类型的Operations使用了WebInvoke。尝试更正这些属性并查看是否有效。接下来,Post方法中缺少ResponseFormat attribute。如果您的配置仅支持Json并且默认格式化程序(在这种情况下它可能是XmlFormatter)阻止它显示在帮助页面上,则可能是这种情况。

如果这不起作用,请在源代码中添加您的端点配置和任何其他自定义配置。

答案 2 :(得分:0)

好吧,我很困惑......

在Internet Explorer中点击CRTL + F5,它可以正常工作。导航器在其缓存中保留了旧版本。

相关问题