There is a public web service that I want to use in a short C # application: http://ws.parlament.ch/
The returned XML from this web service has a โspecificationโ at first, which causes RESTSharp to complete XML deserialization with the following error message:
Error receiving response. Check internal data for more information. ---> System.Xml.XmlException: Data at the root level is not valid. Line 1, position 1. in System.Xml.XmlTextReaderImpl.Throw (exception e)
in System.Xml.XmlTextReaderImpl.Throw (String res, String arg) in System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace () at System.Xml.XmlTextReaderImpl.ParseDocumentContent () in System.Xml.XmlTextReaderImpl.Xml (). Linq.XDocument.Load (XmlReader reader, LoadOptions parameters) in System.Xml.Linq.XDocument.Parse (line text, LoadOptions parameters)
in System.Xml.Linq.XDocument.Parse (string text) in RestSharp.Deserializers.XmlDeserializer.Deserialize [T] (IRestResponse response) in RestSharp.RestClient.Deserialize [T] (IRestRequest request, IRestResponse raw)
--- End of internal exception stack trace ---
Here is a simple example using http://ws.parlament.ch/sessions?format=xml to get a list of "sessions":
public class Session { public int Id { get; set; } public DateTime? Updated { get; set; } public int? Code { get; set; } public DateTime? From { get; set; } public string Name { get; set; } public DateTime? To { get; set; } } static void Main(string[] args) { var request = new RestRequest(); request.RequestFormat = DataFormat.Xml; request.Resource = "sessions"; request.AddParameter("format", "xml"); var client = new RestClient("http://ws.parlament.ch/"); var response = client.Execute<List<Session>>(request); if (response.ErrorException != null) { const string message = "Error retrieving response. Check inner details for more info."; var ex = new ApplicationException(message, response.ErrorException); Console.WriteLine(ex); } List<Session> test = response.Data; Console.Read(); }
When I first process the returned xml with Fiddler to remove the first 3 bits ("specification"), the above code works! Can someone please help me deal with this right in RESTSharp? What am I doing wrong? THANKS in advance!
source share