i've been using a wcf rest service in my application and
when i execute the following code i get an error message as The remote server returned an error: (400) Bad Request var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://one/two/servicename.svc/mymethod"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = "{ \"method\": \"send\", " + " \"params\": [ " + " \"param1:value1\", " + " \"param2:value2" + " ] " + "}"; streamWriter.Write(json); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var responseText = streamReader.ReadToEnd(); //Now you have your response. //or false depending on information in the response } how ever i do get the required results when using in script as follows <script> function getdata() { Type = "POST"; Url = "http://one/two/servicename.svc/mymethod"; Data='{"param1": "value1","param2": "value2"}'; ContentType = "application/json; charset=utf-8"; DataType = "json"; ProcessData = true; CallService(); } function CallService() { jQuery.ajax({ type: Type, //GET or POST or PUT or DELETE verb url: Url, // Location of the service data: Data, //Data sent to server contentType: ContentType, // content type sent to server dataType: DataType, //Expected data format from server processdata: ProcessData, //True or False success: function (msg) {//On Successfull service call ServiceSucceeded(msg,title); }, error: ServiceFailed// When Service call fails }); } function ServiceFailed(result) { alert('Service call failed: ' + result.status + '' + result.statusText); Type = null; varUrl = null; Data = null; ContentType = null; DataType = null; ProcessData = null; } function ServiceSucceeded(result,title) { if (DataType == "json") { alert(result.obj1.ErrorFlag); } } } function ServiceFailed(xhr) { alert(xhr.responseText); if (xhr.responseText) { var err = xhr.responseText; if (err) error(err); else error({ Message: "Unknown server error." }) } } </script> can anybody help me on this earlier help is highly appreciated -- You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to dotnetdevelopment@googlegroups.com To unsubscribe from this group, send email to dotnetdevelopment+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en or visit the group website at http://megasolutions.net