tags:

views:

44

answers:

3

I have this certain method(snippet below) for which I want to get the XML result of.

Server

[OperationContract]
[WebGet(UriTemplate = "getcustomerschema/userCode={userCode}/password={password}",
     ResponseFormat= WebMessageFormat.Xml, 
     RequestFormat= WebMessageFormat.Xml, 
     BodyStyle= WebMessageBodyStyle.Wrapped)]
public DataSet GetCustomerSchema(string userCode, string password)
{
     //method     
}

Client

using (HttpResponseMessage response = m_RestHttpClient.Get("getcustomerschema/userCode=admin/password=admin"))
{
   //how can I get the xml resuly from the httpResponseMessage?
}

Thanks

A: 

Why do you need the xml result directly?

You can use Fiddler to see the xml received from the web service if that is what you are after.

It is also possible to call the web service directly from Visual Studio in the Add Web Reference dialog.

Rune Grimstad
Thanks for the suggestion Rune....i actually use fiddler to debug..my concern was how can i get the raw xml in a client application. Thanks
Ravi
A: 

Using HttpResponseMessage you can access the xml response via the "Content" property.

HttpResponseMessage resp = http.Get("friends_timeline.xml");
resp.EnsureStatusIsSuccessful();
XElement document = resp.Content.ReadAsXElement();

Pulled from: http://msdn.microsoft.com/en-us/library/ee391967.aspx

Duke of Muppets
Can only be: ReadByByte(), ReadByStream() or ReadByString().... how did you get ReadAsXlement() <--- did you add another reference or?
Ravi
"Remember, you’ll need a reference to the Microsoft.Http.Extensions assembly and you’ll need to add a using statement to the file for System.Xml.Linq – assuming you’ve done both of these steps, you should see ReadAsXElement within intellisense on the Content property." - http://msdn.microsoft.com/en-us/library/ee391967.aspx
Duke of Muppets
A: 

DataSet dst = new DataSet(); dst.ReadXml(response.Content.ReadAsStream(), XmlReadMode.ReadSchema);

This is how I convert a HttpResponse to a data set then if I need the XML i just extract this from the data set

Hopefully this helps other REST developers

Ravi