I have the following method in my WCF service:
[OperationContract]
[WebInvoke(Method = \"POST\", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessag
I don't think you can pass 2 parameters with a POST
operation for the framework to deserialize it automatically. You have try some of the below approaches:
Define your WCF method to be as below:
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml,
URITemplate="/GetOne/{param1}")]
public int GetOne(string param1, string param2)
{
return 1;
}
Your raw POST request would looks like as below:
POST http://localhost/SampleService/RestService/ValidateUser/myparam1 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/xml
Host: localhost
Content-Length: 86
my param2
Change your WCF REST method to be as below:
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
public int GetOne(string param1, string param2)
{
return 1;
}
Now your raw request should looks something like below:
POST http://localhost/SampleService/RestService/ValidateUser HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost
Content-Length: 86
{"param1":"my param1","param2":"my param 2"}
Change your WCF REST method to be as below:
[OperationContract]
[WebInvoke(Method="POST",
BodyStyle=WebMessageBodyStyle.WrappedRequest,
ResponseFormat=WebMessageFormat.Xml,
RequestFormat= WebMessageFormat.Xml)]
public int GetOne(string param1, string param2)
{
return 1;
}
Now your raw request would look like something below:
POST http://localhost/SampleService/RestService/ValidateUser HTTP/1.1
User-Agent: Fiddler
Content-Type: application/xml
Host: localhost
Content-Length: 116
my param1 myparam2