There is an answered question
here but my case is a little different.
1) it's not a REST service
2) it has custom username-password validation
what I need is to call the service using HttpWebRequest "POST" method with JSON request and response format; this is what I have so far...
public class Service : IService
{
public string SayHello(string name)
{
return String.Format("Hello {0}!", name);
}
}
and
public interface IService
{
[OperationContract]
string SayHello(string name);
}
What I need to have is something like this...
HttpWebRequest request = WebRequest.Create("http://localhost:56779/BeSTService.svc/SayHello") as HttpWebRequest;
string parameters = "{\"name\":\"Umais\"}";
request.Method = "POST";
request.ContentLength = 0;
request.ContentType = "application/json";
if (!string.IsNullOrEmpty(parameters))
{
byte[] byteArray = Encoding.UTF8.GetBytes(parameters);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
I need to use wsHttpBinding as I'm unable to implement the same authentication in webHttpBinding. The wsHttpBinding is working (with authentication) in windows application; however, I need to call this service as HttpWebResponse,HttpWebRequest as well. Please help me out here! I get "Bad Request" error.