WCF REST服务 - HTTP / 1.1 400错误请求 [英] WCF REST Service - HTTP/1.1 400 Bad Request
问题描述
大家好,
i一直在敲打我的脑袋,但无法找到此错误的原因。我有一个WCF REST POST Web服务。每当我在fiddler中调用服务时,都会收到HTTP / 1.1 400 Bad Request。我使用Visual Studio的REST模板40(cs)来创建这项服务。
该服务看起来像
Hi All,
i have been banging my head all day but unable to find the reason for this error. I have a WCF REST POST web service. Whenever I am calling the service in fiddler, getting HTTP/1.1 400 Bad Request. I have used Visual Studio's REST template 40(cs) to create this service.
The service looks like
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, MaxItemsInObjectGraph = 2147480)]
public class iHubService
{
[WebInvoke(UriTemplate = "LoginUser", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public LogInRes LoginUser(LogInReq objloginReq)
{
LogInRes objLoginRes = new LogInRes();
iHubBusiness.LogIn_BAL objLogIn = new LogIn_BAL();
try
{
objLoginRes = objLogIn.LogInUser(objloginReq);
}
catch
{
}
}
}
Web.config是
The Web.config is
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<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>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding>
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<!--END-->
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<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" defaultOutgoingResponseFormat="Json" maxReceivedMessageSize="1000000"
maxBufferPoolSize="1000000" maxBufferSize="1000000"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
当我在IE中看到此服务的帮助文件时,请求JSON格式格式是
When I see the help file for this service in IE, the request JSON format format is
{
"AppType":"String content",
"Password":"String content",
"Username":"String content"
}
即使传递此默认数据,我也会在Fiddler中得到以下错误
Even on passing this default data, I get below error in Fiddler
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Length: 1790
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 10 Oct 2013 16:07:53 GMT
<?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="https://172.16.3.25/Test/iHubWebService/iHubService/help">service help page</a> for constructing valid requests to the service.</p>
</div>
</body>
我在内容中使用了content-type:application / json提琴手。
我整天都对这个问题感到困扰。有什么方法可以检查40错误的原因。任何建议都是最受欢迎的。
I have used content-type:application/json in the fiddler.
I have been troubled with this issue the whole day. Is there any way I can check the reason for 40 error. Any suggestion are most welcome.
推荐答案
在发布到WCF RESTful Web服务时,HTTP 400错误请求的解决方案 [ ^ ]
编辑
-------------------
您没有共享其他错误消息(400 Bad Request不是绝对错误消息) 。确保您使用的是正确的内容类型&数据类型。并使用适当的异常处理来获取与错误相关的更多详细信息。检查这些。
使用JQuery进行基于WCF REST的服务调用 [ ^ ]
使用WCF和& ;;进行有效的错误处理REST [ ^ ]
WCF和JSON服务 [ ^ ]
将文件作为Base64字符串发送到WCF RESTful服务 [ ^ ]
WCF POST测试工具 [ ^ ]
WCF REST异常处理 [ ^ ]
Solution to HTTP 400 Bad Request when POSTing to WCF RESTful web service[^]
EDIT
-------------------
You didn't share the additional error message(400 Bad Request is not an absolute error message). Make sure you're using right content-type & datatype. And use proper exception handling to get more details related to errors. Check these.
WCF REST Based Service Call using JQuery[^]
Effective Error Handling with WCF & REST[^]
WCF and JSON Services[^]
Sending files as a Base64 String to a WCF RESTful Service[^]
WCF POST test harness[^]
WCF REST Exception handling [^]
这篇关于WCF REST服务 - HTTP / 1.1 400错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!