Topics: Web Client Software Factory, Project Management Forum, User Forum
Jul 7, 2009 at 2:12 PM
Edited Jul 8, 2009 at 12:00 PM


I have to consume the Create(POST)  method  written using the WCF REST and the
REST framework is developed based on the WCF Rest starter kit preview 2. I have to use WebClient for consuming the service.

It throws Bad Request

Please find some of the code snippet below,

Uri logUri = new Uri(Convert.ToString(ConfigurationManager.AppSettings["SvcUri"]) + "TestSvc/test.svc/Create");
            WebClient webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/xml");//; charset=utf-8
            webClient.Encoding = Encoding.UTF8;
            webClient.Credentials = CredentialCache.DefaultNetworkCredentials;

            Serializable.Test request = new Serializable.Test();
            request.Id = 1;
            request.ProcessName = "test";

               StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);

            XmlSerializer serializer = new XmlSerializer(typeofSerializable.Log));
            serializer.Serialize(xw, request);

                string result = webClient.UploadString(logUri, "POST", sw.ToString());
            catch (Exception ex)
                var exec = ex.InnerException;


The above code returns bad request

If possible can you send is there is any code for doing POST using WebClient


Advance thanks for the help !!!