emblewembl
Programmer
I am developing a web service which will output a string which the user of the web service can then convert to xml and do whatever they like with it! I am serializing my object then returning the string and it's all working fine. However, I have built a test website to access the webservice and when I try to converty the text to xml I get an error msg saying the first character is invalid.
Here is the serialization code in the webservice:
And in the test website I am doing this to get the string out of the webservice and convert to xml:
The error msg I get is:
Just before this line:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
there is a weird character, like a small square. Where is this coming from and what am I doing wrong? Is the problem at the web service side of things or in the test web site? Hope you can help!
i love chocolate
Here is the serialization code in the webservice:
Code:
[WebMethod]
public string GetRP(string TrackId, string RaceDate, string RaceNumber, bool Surface, bool Track, bool Life)
{
Serialization ser = new Serialization();
string outString = ser.Serialize(prediction);
}
public string Serialize(object objName)
{
try
{
string XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(Prediction));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, objName);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
XmlizedString = XmlizedString.Trim();
return XmlizedString;
}
catch (Exception e)
{
return null;
}
}
private string UTF8ByteArrayToString(byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
string constructedString = encoding.GetString(characters);
return (constructedString);
}
And in the test website I am doing this to get the string out of the webservice and convert to xml:
Code:
PredictorWS.Service pws = new PredictorWS.Service();
string prediction = pws.GetRacePrediction("B", "14/06/2006", "1", true, true, true);
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(prediction);
The error msg I get is:
Code:
Data at the root level is invalid. Line 1, position 1.
Just before this line:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
there is a weird character, like a small square. Where is this coming from and what am I doing wrong? Is the problem at the web service side of things or in the test web site? Hope you can help!
i love chocolate