【发布时间】:2011-03-22 10:54:37
【问题描述】:
我有方法必须添加客户:
[WebInvoke(UriTemplate = "/", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
string CreateCustomer(Customer customer);
我有一个问题,因为对这个方法的所有调用都失败了! GET 的相同方法运行良好(只需在 url 中返回 Customer 对象 bu 请求 id)。 wcf 服务的响应:
Status: 400
headers = {
"Cache-Control" = private;
"Content-Length" = 2900;
"Content-Type" = "text/html";
Date = "Tue, 22 Mar 2011 12:51:09 GMT";
Server = "Microsoft-IIS/7.0";
"X-Aspnet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
}
<!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>
我无法调试方法,因为在方法步骤之前出现问题。
我认为我的第一个论点存在问题客户客户 如何POST正确?以及如何使用它(Parse json on server)?
在提琴手中
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</BODY></HTML>
但我不确定这与客户遇到的问题相同!
【问题讨论】:
-
有一个名为 Fiddler 的工具可以查看客户端和服务器之间发送的内容,我在为 WCF REST 服务开发 PoC 时使用了它 - 它非常有用:fiddler2.com/fiddler2
-
我用它。并且不知道出了什么问题!
标签: .net wcf web-services json rest