I have a WebGet method, how can I get the xml result?
I have this certain method(snippet below) for which I want to get the XML result of.
Server
[OperationContract]
[WebGet(UriTemplate = "getcustomer开发者_如何学Goschema/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
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
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.
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
精彩评论