locked
Getting error while posting soap xml using webclient RRS feed

  • Question

  • User136609187 posted

    Iam trying to post an XML request to a WCF service directly using webclient as below.

    using (var client = new WebClient())

    {
    var requestdata = File.ReadAllText(@"C:/ConversionRequest.xml");

    client.Headers.Add("Content-Type", "text/xml;charset=utf-8");

    client.Headers.Add("SOAPAction", "urn:IService1:ConversionService:ConversionReq");

    var response = client.UploadString("http://10.15.211.182:1809/ConversionService.svc", requestdata);

    }


    when I execute am getting "The remote server returned an error: (500) Internal Server Error."

    I tried the same with Webrequest as well but getting the same error .


     string url = "http://10.15.211.182:1809/ConversionService.svc";
     XmlDocument xml = new XmlDocument();
     xml.Load(@"C:/ConversionRequest.xml");
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
     request.Method = "POST";
     request.ContentType = "text/xml";
     Stream reqStream = request.GetRequestStream();
     xml.Save(reqStream);
     reqStream.Close();
     HttpWebResponse reponse = (HttpWebResponse)request.GetResponse();
     Stream rspStream = reponse.GetResponseStream();
     StreamReader rsp_Stream = new StreamReader(rspStream, System.Text.Encoding.GetEncoding("utf-8"));
     string output = rsp_Stream.ReadToEnd();
     rsp_Stream.Close();
     


    This is my Service  Operation contract

    ConversionResponse ConvertData(ConversionReq request)

    below is the stack trace not getting any idea ..

    System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
    Statuscode: protocol error
       at System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest& request)
       at System.Net.WebClient.UploadString(Uri address, String method, String data)
       at System.Net.WebClient.UploadString(String address, String data)
     
    Please help me out

    Tuesday, July 16, 2013 8:14 AM

Answers