Restful WCF service POST方法在fiddler2中返回HTTP400错误

Restful WCF service POST方法在fiddler2中返回HTTP400错误,wcf,post,fiddler,wcf-rest,Wcf,Post,Fiddler,Wcf Rest,已创建用于登录验证的简单Restful服务。下面是我的接口和类定义 接口IDemo: public interface IDemo { [OperationContract] [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Ba

已创建用于登录验证的简单Restful服务。下面是我的接口和类定义

接口IDemo:

public interface IDemo
{
    [OperationContract]
    [WebInvoke(RequestFormat = WebMessageFormat.Json,
               ResponseFormat = WebMessageFormat.Json,
               BodyStyle = WebMessageBodyStyle.Bare,
               UriTemplate = "/ValidateUser?Username={UserName}&Password={Password}",
               Method = "POST")]
    string  ValidateUser(string Username, string Password);
}
课堂演示:

public class Demo:IDemo
{
    public string ValidateUser(string Username, string Password)
    {
        Users objUser = new Users();
        objUser.UserID = Username;
        objUser.Password = Password;
        string Msg = LoginDataService.ValidateUser(Username, Password);
        return Msg;
    }
}
localhost:49922/Demo.svc/ValidateUser?Username=Demo&Password=Demo(带http:\)

当我试图在Fiddler2中的Post方法下解析上述URL时,我得到了错误的请求HTTP400错误

有人能帮我找出代码中的错误吗

谢谢和问候


Vijay

您的URI模板看起来像是在URL中发送参数。但是使用POST时,参数将在http正文中发送


注意:您不应该在url中发送用户名和密码,因为它可以被记录。

对于上述REST方法,来自Fiddler的帖子需要如下所示:

POST http://localhost/Sample/Sample.svc/ValidateUser?Username=demo&Password=demo HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: rajeshwin7
Content-Length: 0
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 44
Content-Type: application/json; charset=utf-8
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 14 Jun 2012 15:35:28 GMT

"Server returns username demo with password demo"
这样,我将返回200 OK HTTP状态,如下所示:

POST http://localhost/Sample/Sample.svc/ValidateUser?Username=demo&Password=demo HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: rajeshwin7
Content-Length: 0
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 44
Content-Type: application/json; charset=utf-8
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 14 Jun 2012 15:35:28 GMT

"Server returns username demo with password demo"

我不知道您的代码可能还有什么其他问题,但是如果您要在查询字符串中指定所有输入参数,您应该将您的服务方法标记为GET而不是POST。如何配置适用的端点&客户端和服务的端点是否相同?Bhajii感谢您的评论。这是一个简单的演示服务,仅此而已..我已经更改了方法,没有参数列表为“/validate”,而且我已经用testclient应用程序对其进行了测试,它工作正常。但是当我用fiddler测试时,我无法得到json结果。。谢谢你的评论…你能发布你的小提琴手原始的请求和回应吗