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
Wcf REST POST请求不工作_Wcf_Rest_Wcf Data Services - Fatal编程技术网

Wcf REST POST请求不工作

Wcf REST POST请求不工作,wcf,rest,wcf-data-services,Wcf,Rest,Wcf Data Services,这是我的WCFRestAPI,它使用POST [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "/Test/{id}")] void Test(string id); 我正在通过url从我的REST DHC客户端调用它 http://local

这是我的WCFRestAPI,它使用POST

 [OperationContract]
 [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "/Test/{id}")]
        void Test(string id);
我正在通过url从我的REST DHC客户端调用它

http://localhost/RestTestWebService.svc/json/Test/abs
现在我得到了不允许的错误方法。

我遗漏了什么,而且日志中也没有我注意到的信息

这是我的web.config-

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <!--<authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>-->

    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>




  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHttpBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>

        <behavior name="RestTestWebServiceBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>      
    </behaviors>

    <services>
      <service name="RestTest.RestTestWebService" behaviorConfiguration="RestTestWebServiceBehaviors" >
        <endpoint name="json" address="json" binding="webHttpBinding" behaviorConfiguration="WebHttpBehavior" contract="RestTest.IRestTestWebService"/>

        <!--<endpoint name="json" address="" binding="basicHttpBinding" contract="RestTest.IRestTestWebService"/>-->
      </service>
    </services>




    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"  />
  </system.serviceModel>
</configuration>

如果您在IIS上托管服务。请检查WebDav配置中是否允许使用“Post”动词

  • 在IIS中,选择您的网站
  • 选择处理程序映射
  • 从映射列表中选择WebDAV
  • 单击请求限制
  • 然后切换到动词选项卡并突出显示所有动词
  • 在IIS中重新启动应用程序
  • 如果仍然不起作用,请尝试以下方法

    • 在IIS中,禁用WebDav

    • 卸载WebDav模块

      服务器管理器->角色->Web服务器->通用HTTP功能->WebDAV发布,以及客户端计算机控制面板->卸载程序->打开或关闭Windows功能->IIS->万维网服务->通用HTTP feautre->WebDAV发布


    Uri必须指定主机号。 必须指定uritemplate:
    “…RestTestWebService.svc/Test/abs”中描述的服务名称后的Uri