Cannot remove escape characters from SOAP message RRS feed

  • Question

  • User620301946 posted

    I have tried several different routines to serialize my XML and each time, after converting to string I get a series of escape characters that are causing problems when POSTing this message to the endpoint.

    <Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">


    <GetMyData xmlns=\"stuff\">

    I have tried Replace I have tried RegEx.Unescape and I cannot remove these escapes. When I run this XML either from code (HttpWebRequest) or from SOAPui with the escapes it fails with a 500. If I remove the escapes it works fine. Any help is appreciated.

    Friday, October 19, 2018 3:32 PM

All replies

  • User475983607 posted

    Is there anyway you can post code that reproduces the issue?  Manually serializing to a SOAP string is unusual.  It could be that you are serializing twice.  

    Friday, October 19, 2018 6:04 PM
  • User-330142929 posted

    Hi msdevtech,

    As far as I know, we could use the xmlserializer to serialize object and return xml string in order to attached to the payload, for Json, we use the JavaScriptSerializer by default.

            public static string Call(BookInfo input)
                string serviceUrl = "http://ws-abrahamq-01:90/Service1.svc/booking";
                StringBuilder sb = new StringBuilder();
                //BookInfo p = new BookInfo()
                //   Name = "abcd"
                XmlSerializer serializer = new XmlSerializer(typeof(BookInfo));
                TextWriter tw = new StringWriter(sb);
                serializer.Serialize(tw, input);
                //string stringPayload = "{\"bookInfo\":" + JsonConvert.SerializeObject(input) + "}";
                string stringPayload1 = sb.ToString();
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(serviceUrl);
                request.ContentType = "application/json";
                request.Method = "POST";
                byte[] body = Encoding.UTF8.GetBytes(stringPayload1);
                request.ContentLength = body.Length;
                request.GetRequestStream().Write(body, 0, body.Length);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string content = reader.ReadToEnd();
                return content;
        public class BookInfo
            public string Name { get; set; }

    I suggest you could post your code so that I could restore your problem with SOAPUI and give you an effective reply.

    Feel free to let me know if you have any questions.

    Best Regards


    Monday, October 22, 2018 3:22 AM