In my current project, I am sending a POST request to a WCF service. But, I am getting empty response. I have tried to use the similar post on stackoverflow : POST1 and [POST2][2] , but I could not solve the problem. My WCF service code is as follows:
namespace RestfulWCFService
{
[OperationContract]
[WebInvoke(Method="GET", ResponseFormat= WebMessageFormat.Xml, UriTemplate="xml/?firstname={firstname}&lastname={lastname}")]
string SayHelloXml(string firstname, string lastname);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "json/{name}")]
string SayHelloJson(string name);
[ServiceContract]
public interface IRestfulTestService
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/data")]
string SayHelloJSONPOSTRequest(string jsonRequestString);
}
}
The implementation of the interface is as follows:
namespace RestfulWCFService
{
string IRestfulTestService.SayHelloXml(string firstname, string lastname)
{
return "Hello " + firstname + " " + lastname;
}
string IRestfulTestService.SayHelloJson(string name)
{
return "Hello " + name;
}
public class RestfulTestService : IRestfulTestService
{
string IRestfulTestService.SayHelloJSONPOSTRequest(string jsonRequestString)
{
return "Hello " + jsonRequestString;
}
}
}
Now, from a REST client, my request is as follow:
http://localhost/RestfulWCFService/RestfulTestService.svc/data
and the Content-Type:application/json
and payload is {"firstname":"Pankesh"}
. I am getting no response from WCF.
For your reference, I am attaching the screenshot of my client.