我在MVVMCross的PCL项目中使用WCF Data Services 5.6。在WPF客户端中,以下代码(在viewModel中)的工作方式类似于魅力(基于http://msdn.microsoft.com/en-us/library/dd756367(v=vs.110).aspx处的示例):
DataServiceQuery<T> query = this.LoadItemsQuery;
query.BeginExecute((result) =>
{
try
{
DataServiceQuery<T> resultQuery = result.AsyncState as DataServiceQuery<T>;
foreach (T item in resultQuery.EndExecute(result))
{
// Do something here
}
}
catch (Exception ex)
{
PublishException(ex);
}
}
, query);
但是在Android客户端中,“resultQuery.EndExecute(result)”会抛出以下异常:
System.InvalidOperationException: An error occurred while processing this request. ---> System.NotImplementedException: The requested feature is not implemented.
at System.Net.WebResponse.get_SupportsHeaders () [0x00000] in <filename unknown>:0
at System.Data.Services.Client.HttpWebRequestMessage.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.ODataRequestMessageWrapper.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.DataServiceContext.GetResponseHelper (System.Data.Services.Client.ODataRequestMessageWrapper request, IAsyncResult asyncResult, Boolean handleWebException) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.DataServiceContext.EndGetResponse (System.Data.Services.Client.ODataRequestMessageWrapper request, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.RequestInfo.EndGetResponse (System.Data.Services.Client.ODataRequestMessageWrapper request, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Data.Services.Client.BaseAsyncResult.EndExecute[QueryResult] (System.Object source, System.String method, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Data.Services.Client.QueryResult.EndExecuteQuery[Appointment] (System.Object source, System.String method, IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 }
有什么想法吗?有人用MonoDroid测试了WCF Data Services 5.6吗?
提前致谢
答案 0 :(得分:1)
https://github.com/mono/mono/blob/master/mcs/class/System/System.Net/WebResponse.cs
您可以从源代码中看到它确实没有实现。
Mono的WCF支持尚未完成,因此将其用于WCF数据服务存在风险。
如果可能的话,在服务器端使用ASP.NET Web API而不是WCF,然后在客户端通过HttpClient获得更好的支持。
答案 1 :(得分:0)
该错误发生在HttpWebResponse.cs中,它应该添加以下内容:
public override bool SupportsHeaders
{
get
{
return true;
}
}
答案 2 :(得分:0)
应该使用最新版本:Mono for Android 4.12.3.I测试并发现它适用于Microsoft.Data.Service.Client.Portable.dll。