Posts

Showing posts from January, 2013

WCF REST Client Console App

The following is the console client, which consumes Rest Service:   using System.Net; using System.IO;   static void RestCall()         {             string baseUri = http://localhost:33987/MyService.svc/GetData/10 ;             HttpWebRequest req = WebRequest .Create(baseUri) as HttpWebRequest ;             HttpWebResponse resp = req.GetResponse() as HttpWebResponse ;             var response = resp.GetResponseStream();             try             {                 StreamReader streamReader = new StreamReader (response, true );                 try                 {                     var target = streamReader.ReadToEnd();                     Console .WriteLine(target);                 }                 finally                 {                     streamReader.Close();                 }             }             finally             {                 response.Close();             }         } App.Config Entries:

WCF REST 400 Bad Request

Today while I was writing my WCF Rest Client, I was getting error as "400 Bad Request". Finally I realized the culprit of error was service name in web.config file. In order to resolve this error, make sure service name is matching with your service markup's service name. If you have servicename1.svc, right click on that file and select "View MarkUp". Copy Service value from that and paste it into webconfig's services service name. Service1.svc MarkUp: <% @ ServiceHost Language ="C#" Debug ="true" Service ="MyServiceNameSpace.Service1" CodeBehind ="Service1.svc.cs" %> Web.config Services Section: < services >    < service name = " MyServiceNameSpace.Service1 " >      < endpoint address = "" behaviorConfiguration = " restService "            contract = " MyServiceNameSpace.IService1 " binding = &