credential obj = new credential();
obj.user = "me";
obj.pwd = "123";
JavaScriptSerializer js = new JavaScriptSerializer();
string postData= js.Serialize(obj);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:52631/Service1.svc/chkUserPwd");
webRequest.Method = "POST";
webRequest.ContentType = "application/json"
webRequest.ContentLength = postData.Length;
try
{
using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter2.Write(postData);
}
using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
{
postData = responseReader.ReadToEnd();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
public class credential
{
public string user { get; set; }
public string pwd { get; set; }
}
As I mentioned on WebInvoke is BodyStyle = WebMessageBodyStyle.Wrapped then we must post the data json or xml.