我正在尝试在Silverlight 5应用程序/ .NET 4.0应用程序中使用WCF数据服务。当我手动查询服务时,我可以在Web浏览器中看到Atom提要的数据。
然而,当我尝试通过标准方法查询数据时,我收到以下错误:
{System.Security.SecurityException:安全错误。 在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)}
内部异常为空。因此尚无有意义的信息可用。
public partial class ProjectWindow : ChildWindow
{
XYZEntitis.XYZEntitis db = new XYZEntitis.XYZEntitis(new Uri("http://google.com/wcfdataservice1.svc/"));
DataServiceCollection<XYZEntitis.Label> dscCats = new DataServiceCollection<XYZEntitis.Label>();
CollectionViewSource customerAddressViewSource;
ObservableCollection<XYZEntitis.Label> labelsBindingCollection = new ObservableCollection<XYZEntitis.Label>();
public ProjectWindow()
{
InitializeComponent();
btnBack.IsEnabled = false;
//Load Project categories
BindProjectCategories();
}
public void BindProjectCategories()
{
#region Code
//#############################################
//Approach # 01 : Raises Security Exception
//#############################################
//DataServiceQuery<XYZEntitis.Label> query = db.Labels;
//query.BeginExecute(
// s =>
// {
// var state = s.AsyncState as DataServiceQuery<XYZEntitis.Label>;
// var data = new ObservableCollection<XYZEntitis.Label>();
// foreach (var entity in state.EndExecute(s))
// data.Add(entity);
// cbCategoryName.ItemsSource = data;
// }, query);
#endregion
//#############################################
//Approach No # 2 : 0 Records are returned
//#############################################
var cats = from cat in db.Labels select cat;
//cats.ToList();
dscCats.LoadCompleted += this.dscCats_LoadCompleted;
dscCats.LoadAsync(cats);
//#############################################
//Approach # 3 : Security Exception
//#############################################
//var query = from cat in db.Labels select cat;
//((DataServiceQuery<XYZEntitis.Label>)query).BeginExecute(OnCategoriesFecthComplete, query);
}
private void OnCategoriesFecthComplete(IAsyncResult ar)
{
var query = ar.AsyncState as DataServiceQuery<XYZEntitis.Label>;
// Get the response of the query.
var response = query.EndExecute(ar);
foreach (XYZEntitis.Label label in response)
{
labelsBindingCollection.Add(label);
}
cbCategoryName.ItemsSource = labelsBindingCollection;
}
private void dscCats_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
if (dscCats.Continuation != null)
{
dscCats.LoadNextPartialSetAsync();
}
else
{
cbCategoryName.ItemsSource = dscCats;
#region code
//var data = (DataServiceCollection<XYZEntitis.Label>)sender;
//cbCategoryName.ItemsSource = data;
//cbCategoryName.DisplayMemberPath = "Name";
//customerAddressViewSource =
// (CollectionViewSource)this.Resources["customerAddressViewSource"];
//customerAddressViewSource.Source = dscCats;
#endregion
}
}
}
System.InvalidOperationException未被用户代码处理 Message =处理此请求时发生错误。 堆栈跟踪: at System.Data.Services.Client.BaseAsyncResult.EndExecute [T](Object source,String method,IAsyncResult asyncResult) 在System.Data.Services.Client.QueryResult.EndExecute [TElement](对象源,IAsyncResult asyncResult) 在System.Data.Services.Client.DataServiceRequest.EndExecute [TElement](对象源,DataServiceContext上下文,IAsyncResult asyncResult) 在System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult) 在ThreatModeler.Silverlight.ProjectWindow.OnCategoriesFecthComplete(IAsyncResult ar) 在System.Data.Services.Client.BaseAsyncResult.HandleCompleted() 在System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult) 在System.Data.Services.Client.BaseAsyncResult。&lt;&gt; c_ DisplayClass1.b _0(IAsyncResult asyncResult) 在System.Net.Browser.ClientHttpWebRequest。&lt;&gt; c_ DisplayClass1a.b _18(Object state2) 在System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(对象状态) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx) 在System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在System.Threading.ThreadPoolWorkQueue.Dispatch() 在System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() InnerException:System.Security.SecurityException 消息=安全错误。 堆栈跟踪: 在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult) InnerException:
{System.InvalidOperationException:处理时发生错误 这个请求。 ---&GT; System.Security.SecurityException:安全性错误。 在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult) asyncResult)at System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult的 asyncResult)at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult的 asyncResult)---内部异常堆栈跟踪结束--- at System.Data.Services.Client.BaseAsyncResult.EndExecute [T](对象 source,String方法,IAsyncResult asyncResult)at System.Data.Services.Client.QueryResult.EndExecute [TElement](对象 source,IAsyncResult asyncResult)at System.Data.Services.Client.DataServiceRequest.EndExecute [TElement](对象 source,DataServiceContext context,IAsyncResult asyncResult)at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult的 asyncResult)at ThreatModeler.Silverlight.ProjectWindow.b_ 0(IAsyncResult的 s)在System.Data.Services.Client.BaseAsyncResult.HandleCompleted() 在 System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult的 asyncResult)at System.Data.Services.Client.BaseAsyncResult&LT;。&以及c _DisplayClass1.b_ 0(IAsyncResult的 asyncResult)at System.Net.Browser.ClientHttpWebRequest&LT;。&以及c _DisplayClass1a.b__18(对象 state2)at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(对象 System.Threading.ExecutionContext.Run(ExecutionContext。) executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在System.Threading.ThreadPoolWorkQueue.Dispatch()at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()}