2010-09-07 58 views
1

我有这个特定的方法(片段下面),我想要得到的XML结果。我有一个WebGet方法,我怎样才能得到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? 
} 

感谢

回答

0

数据集DST =新的DataSet(); dst.ReadXml(response.Content.ReadAsStream(),XmlReadMode.ReadSchema);

这是我如何转换的HttpResponse的数据的集合,然后,如果我需要的XML我刚刚从数据中提取此设置

希望这有助于其他REST开发商

0

为什么你需要直接XML结果?

您可以使用Fiddler来查看从Web服务接收到的xml,如果这是您所追求的。

也可以在添加Web引用对话框中直接从Visual Studio中调用Web服务。

+0

感谢您的建议符文... .i实际上使用fiddler来调试。我关心的是如何在客户端应用程序中获取原始xml。谢谢 – Ravi 2010-09-08 10:59:39

1

使用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

+0

只能是:ReadByByte(),ReadByStream()或ReadByString()....你是如何得到ReadAsXlement()<---你添加了另一个引用或? – Ravi 2010-09-08 10:58:55

+1

“请记住,您需要引用Microsoft.Http.Extensions程序集,并且需要为System.Xml.Linq的文件添加using语句 - 假设您已完成这两个步骤,则应该请参阅Content属性的intellisense中的ReadAsXElement。“ - http://msdn.microsoft.com/en-us/library/ee391967.aspx – 2010-09-09 08:59:39