c# - 我有一个 WebGet 方法,如何获取 xml 结果?

标签 c# xml http rest

我有这个特定的方法(下面的片段),我想为它获取 XML 结果。

服务器

[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     
}

客户端

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

谢谢

最佳答案

使用 HttpResponseMessage,您可以通过“Content”属性访问 xml 响应。

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

来自:http://msdn.microsoft.com/en-us/library/ee391967.aspx

关于c# - 我有一个 WebGet 方法,如何获取 xml 结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3656849/

相关文章:

http - 为什么 `http`包需要地址引用?

c# - App.config 文件中的连接字符串,用于从本地计算机连接到 EC2 SQL Server 2008 R2

c# - 赋值前的冗余比较 & "if"

c# - 如何使用 HTML Agility Pack 清理格式错误的 HTML

c# - xml和xslt之间的转换处理时如何产生异常错误

java - httpclient (phpmyadmin) 不适用于 Android 4.0+

c# - PartialClassGenerationTask 和 MarkupCompilePass1 如何一起工作/属于

xml - 使用 XML 数据和 XPath 的 SSRS

xml - 从字符串或字节数组创建 XML 解码器 GO

javascript - 如何拦截浏览器发出的 HTTP 请求?