Fiddler POST到REST服务端点出错400错误

时间:2012-06-29 17:13:27

标签: wcf rest post

我有一个简单的REST服务端点,当我使用Fiddler 2 POST时失败。不需要输入参数的端点成功。只传入数据会导致失败。我正在使用集成到VS 2010中的Web服务器。

详细说明:

Global.asax条目

private void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes();
        }
    private void RegisterRoutes()
        {
            RouteTable.Routes.Add(new ServiceRoute("Employee", new WebServiceHostFactory(), typeof(Employee)));
            RouteTable.Routes.Add(new ServiceRoute("Provider", new WebServiceHostFactory(), typeof(Provider)));
        }

网络服务:

[ServiceContract]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
        public class Provider : BaseMvpWebService<ProviderPresenter>, IProvider

    [WebInvoke(Method="POST", RequestFormat=WebMessageFormat.Json, UriTemplate="",      ResponseFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped)]
        public ProviderListWrap FilteredList(GeneralSearchView filtersearch)
    { ... }

网络配置条目:

    <system.serviceModel>
        <standardEndpoints>
          <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>     

参数类型定义:

 [DataContract]
 public class GeneralSearchView : IGeneralSearchView
 {
    [DataMember]
    public string ProviderListing { get; set; }

    [DataMember]
    public string FundingSource { get; set; }

    [DataMember]
    public string ProviderType { get; set; }

    [DataMember]
    public string ServiceType { get; set; }

    [DataMember]
    public string UserZipCode { get; set; }

    [DataMember]
    public string SearchRadius { get; set; }

    [DataMember]
    public string SearchCounty { get; set; }
 }

通过Fiddler 2发布:

POST  http://localhost:19099/Provider/

请求标题

User-Agent: Fiddler
Content-Type: application\json
Host: localhost:19099
Content-Length: 43

请求正文

{"filtersearch":{"ProviderListing":"True"}}

原始回复

HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 29 Jun 2012 17:31:35 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 1770
Set-Cookie: ASP.NET_SessionId=qgvgtxlcvdouut2qgq40u4eh; path=/; HttpOnly
Cache-Control: private
Content-Type: text/html
Connection: Close

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Request Error</title>
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
  </head>
  <body>
    <div id="content">
      <p class="heading1">Request Error</p>
      <p xmlns="">The server encountered an error processing the request. Please see the <a rel="help-page" href="http://localhost:19099/Provider/help">service help page</a> for constructing valid requests to the service.</p>
    </div>
  </body>
</html>

任何想法/反馈都将不胜感激。 谢谢!

1 个答案:

答案 0 :(得分:1)

我认为您的内容类型斜杠可能存在语法问题。 尝试:

Content-Type:application / json

如果没有,响应中是否还有其他详细信息?只有400个不好的请求?