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.
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.
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.
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();
response.Close();
reader.Close();
request.Abort();
response.Close();
return content;
}
}
[DataContract]
public class BookInfo
{
[DataMember]
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
Abraham
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
3 Posts
Cannot remove escape characters from SOAP message
Oct 19, 2018 03:32 PM|msdevtech|LINK
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/\">
<Body>
<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.
All-Star
53131 Points
23682 Posts
Re: Cannot remove escape characters from SOAP message
Oct 19, 2018 06:04 PM|mgebhard|LINK
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.
Member
740 Points
321 Posts
Re: Cannot remove escape characters from SOAP message
Oct 22, 2018 03:22 AM|Abraham Qian|LINK
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.
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
Abraham