I have a WCF RESTful service that is supposed to return a name and surname of a customer as a XML response, the service is defined as indicated below
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/GetNameAndSurname")]
string GetNameAndSurname();
The problem I'm experiencing is that the XML response that is returned was not in normal XML as expected, for example
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
<Customer;
<Name>Andre</Name>
<SurnameName>Lombaard</SurnameName>
>
</string>
I'm not sure if it is the service returning the response this way or if it is the way I'm reading the data, just for informational purposes I included the code I use to read the response below,
var request = HttpWebRequest.Create(url);
request.Method = "POST";
request.Timeout = 2 * 60 * 1000;
byte[] byteArray = Encoding.UTF8.GetBytes(xml);
request.ContentType = "text/xml";
request.ContentLength = byteArray.Length;
var dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
var response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
dataStream.Flush();
var results = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
How do I get normal XML without having to perform various replacements on the characters received in the response.
At the moment I replace the characters with the code below. This is not ideal
results = results.Replace("</string>", String.Empty);
results = results.Replace("<", "<");
results = results.Replace(">
", ">");
results = results.Replace(">", ">");
results = Regex.Replace(results, "<string .*?\\>", String.Empty);