tags:

views:

692

answers:

3

I'm actually playing around with the last.FM web serivce API which I call via REST. When I get the response I try to convert the result into a XDocument so I could use LINQ to work with it.

But when I pass the result string to the XDocumnet constructor an ArgumentException is thrown telling me that "Non white space characters cannot be added to content.". Unfortunately I'm very new to web services and XML programming so I don't really know how to interpret this exception.

I hope someone could give me a hint how to solve this problem.

+1  A: 

http://jamescrisp.org/2008/08/08/simple-rest-client/ has posted a little REST Client. Maybe a starting point for you.

Sebastian Sedlak
Thanks, I will take a look at this blog post.
Flo
+1  A: 

It sounds to me as though you are holding the response in a string. If that is the case, you can try to use the Parse method on XDocument which is for parsing XML out of a string.

string myResult = "<?xml blahblahblah>";
XDocument doc = XDocument.Parse(myResult);

This may or may not solve your problem. Just a suggestion that is worth a try to see if you get a different result.

Lusid
+2  A: 

Here's a sample you can use to query the service:

class Program
{
    static void Main(string[] args)
    {
        using (WebClient client = new WebClient())
        using (Stream stream = client.OpenRead("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&amp;api_key=b25b959554ed76058ac220b7b2e0a026&amp;artist=Cher&amp;album=Believe"))
        using (TextReader reader = new StreamReader(stream))
        {
            XDocument xdoc = XDocument.Load(reader);
            var summaries = from element in xdoc.Descendants()
                    where element.Name == "summary"
                    select element;
            foreach (var summary in summaries)
            {
                Console.WriteLine(summary.Value);
            }
        }
    }
}
Darin Dimitrov
You can just do XDocument doc = XDocument.Load("http://www...");If I am remembering correctly.Dave
David Gouge