Hello, I cannot help you on your code, but last time when I write a service that offering WCF restful service, I use WCF Web API(http://wcf.codeplex.com/wikipage?title=WCF%20Web%20API%20is%20now %20ASP.NET%20Web%20API), it's really easy to use, because you don't have to write code to compose request and parse response, all you need to do is focusing on your business rule. Another awesome point is there's a test tool integrated in the API.
If you just on the start point of your project, I strongly recommend you give it a try. Cheng On Jun 18, 8:27 pm, kalyan <kali...@gmail.com> wrote: > 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