REST POST请求不起作用

时间:2014-06-04 05:10:21

标签: wcf rest wcf-data-services

这是我使用POST的WCF Rest Api。

 [OperationContract]
 [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "/Test/{id}")]
        void Test(string id);

我通过网址

从我的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>

2 个答案:

答案 0 :(得分:1)

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

  1. 在IIS中,选择您的网站
  2. 选择处理程序映射
  3. 从映射列表中选择WebDAV
  4. 点击请求限制
  5. 然后切换到动词选项卡并突出显示所有动词
  6. 在IIS中重新启动应用程序。
  7. 如果仍然无效,请尝试以下方式。

    • 在IIS中,禁用您的WebDav。

    • 卸载WebDav模块。

      服务器管理器 - &gt;角色 - &gt; Web服务器 - &gt;常见的HTTP功能 - &gt; WebDAV发布,以及客户机控制面板 - &gt;卸载程序 - &gt;打开或关闭Windows功能 - &gt; IIS - &gt;万维网服务 - &gt;常见的HTTP feautre - &gt; WebDAV Publishing。

答案 1 :(得分:0)

Uri必须指定主机号码。 必须指定uritemplate:"...RestTestWebService.svc / Test / abs"

中描述的服务名称后的Uri
相关问题