Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的WCF帮助页面只显示GET方法?_C#_Wcf_Rest_Iis - Fatal编程技术网

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

C# 为什么我的WCF帮助页面只显示GET方法?,c#,wcf,rest,iis,C#,Wcf,Rest,Iis,我有一个WCF REST服务,在WCF服务应用程序中托管了以下合约: [ServiceContract] public interface IService { [OperationContract] [WebInvoke(Method="GET", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate="key

我有一个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);
}
谢谢你的帮助

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

更新2:天哪!它在IIS上工作

在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>


你把两件事混在一起了。下面是关于WebGet和WebInvoke的快速信息。
WebGet
代表HttpGet操作。
WebInvoke
代表Post请求,例如
httpput
httpdelete
httppost
操作

您仅对这两种类型的操作使用了WebInvoke。请尝试更正这些属性,看看是否有效。接下来,Post方法中缺少
ResponseFormat属性
。如果您的配置只支持Json,而默认格式化程序(在本例中可能是XmlFormatter)正在抑制Json以显示在帮助页面上,则可能会出现这种情况

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

嗯,我很困惑


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

我决定在我的两台同事机器上测试同一个项目,在这两种情况下都能很好地工作!这个问题显然与我的环境有关。
  <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>