0

have created simple Restful service for log in verification. Following are my interface and class definitions.

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

Class Demo :

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 (with http:\)

When I try to parse the above URL under the Post Method in Fiddler2 I got Bad Request HTTP400 error.

Can anyone help me what is wrong in my code.

Thanks & Regards,

Vijay

VijayMathew
  • 55
  • 1
  • 10
  • 1
    I don't know what other issues there may be with your code, but if you are going to specify all of your input parameters in the query string you should mark your service method as GET instead of POST. – Mark M Jun 13 '12 at 13:15
  • How is the applicable endpoint configured & is it the same for both client and service? – Mark M Jun 13 '12 at 13:27
  • Bhajii Thanks for your comment . it is simple demo service that's all.. – VijayMathew Jun 16 '12 at 10:21

2 Answers2

1

Your URI template looks like you are sending the parameters in the URL. But when you use POST the parameters are sent in the http body.

Note you should not send the username and passord in the url as it can be logged.

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
0

For the above REST method the POST from Fiddler needs to be as shown below:

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

Doing so i get back a 200 OK HTTP Status as shown below:

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"
Rajesh
  • 7,766
  • 5
  • 22
  • 35
  • I have changed the Method without parameter list as "/validate" and also i have tested it with testclient application it is working fine. but when I test this with fiddler i could not get the json result back.. Thanks for ur comment... – VijayMathew Jun 16 '12 at 10:23
  • Can you post your fiddlers raw request and response – Rajesh Jun 16 '12 at 15:56