[英]How to get JSON from a WCF Data Services, DataServiceQuery call in Silverlight?
背景:我有一個帶有Silverlight應用程序的WCF數據服務,該應用程序當前正在使用atom pub xml。 我想使用JSON來減少有效負載的大小。 我讀到您可以使用以下代碼從服務Webget進行JSON:
WebClient wc = new WebClient();
wc.Headers["Accept"] = "application/json";
我可以修改DataServiceQuery調用的頭還是localContext.BeginExecute(對於WebGets)嗎?
// 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);
即使您要修改DataServiceRequest的標頭,WCF DS的客戶端庫也不支持讀取JSON響應,因此它將無法讀取響應。 當前建議的減少有效載荷大小的方法是使用GZip。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.