2012-06-29 37 views
2

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

详情:

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

Web服务:

[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) 
    { ... } 

Web配置项:

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

参数类型定义:经由提琴手2

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

张贴:

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

我在想你可能有你的内容类型斜杠的语法问题。 尝试:

内容类型:应用程序/ JSON

如果不是,是否有在响应任何其他细节?只有400个不好的要求?

+0

对不起。刚添加了回复。 – user1491690

+0

是的,你绝对正确!错误的斜线。抱歉,添麻烦了。我会睡一会儿! – user1491690

相关问题