【问题标题】:How to get JSON from a WCF Data Services, DataServiceQuery call in Silverlight?如何从 Silverlight 中的 WCF 数据服务、DataServiceQuery 调用中获取 JSON?
【发布时间】:2012-02-21 20:00:13
【问题描述】:

背景:我有一个带有 Silverlight 应用程序的 WCF 数据服务,该应用程序当前正在使用 atom pub xml。我想使用 JSON 来减小有效负载的大小。 我读到您可以使用以下代码从服务 webget 获取 JSON:

WebClient wc = new WebClient();
wc.Headers["Accept"] = "application/json";

我可以修改 DataServiceQuery 调用或 localContext.BeginExecute(用于 WebGet)的标头吗?

// WCF Data Services Query Proxy
DataServiceQuery<T> query = filterExpression as DataServiceQuery<T>;

// Execute the ASYNC query against the model
query.BeginExecute(new AsyncCallback((iar) =>
{ ...});

// Create new context with the WCF service to force only save this entity
VisiconnEDM localContext = new VisiconnEDM(new Uri(entityServiceURL, UriKind.Absolute));

// execute the query asynchronously 
localContext.BeginExecute<T>(urlQuery,(IAsyncResult iar) =>{ ...},null);

【问题讨论】:

    标签: json silverlight wcf-data-services


    【解决方案1】:

    即使您要修改 DataServiceRequest 的标头,WCF DS 的客户端库也不支持读取 JSON 响应,因此它无法读取响应。目前建议的减小负载大小的方法是使用 GZip。

    【讨论】:

    • 感谢您(再次)为我指明正确的方向。我也感谢您在过去回答我的问题。我查找了有关使用 GZip 的信息,但没有找到好的链接。你有推荐吗? (我们的服务器还没有 IIS 7)
    • GZip 几乎是特定于网络服务器的,因此您的赌注将是在这方面提出一个单独的问题。不幸的是,我对此知之甚少。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    相关资源
    最近更新 更多