C# 4.0 OperationException:处理时出错 此请求。-->System.Security.SecurityException:安全错误。 在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult)中 异步结果)在 System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult 异步结果)在 System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)--内部异常堆栈跟踪的结束---at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](对象 源、字符串方法、IAsyncResult异步结果)位于 System.Data.Services.Client.QueryResult.EndExecute[TElement](对象 源,IAsyncResult(异步结果)位于 System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](对象 源,DataServiceContext上下文,IAsyncResult asyncResult)位于 System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult 异步结果)在 ThreatModeler.Silverlight.ProjectWindow.b_0(IAsyncResult s) 位于System.Data.Services.Client.BaseAsyncResult.HandleCompleted()处 在 System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult 异步结果)在 System.Data.Services.Client.BaseAsyncResult.c_DisplayClass1.b_0(IAsyncResult 异步结果)在 System.Net.Browser.ClientHttpWebRequest.c_DisplayClass1a.b_u18(对象 (2)在 System.Threading.QueueUserWorkItemCallback.WaitCallback\u上下文(对象 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback回调、对象状态、布尔值 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 位于System.Threading.ThreadPoolWorkQueue.Dispatch()的 System.Threading.\u ThreadPoolWaitCallback.PerformWaitCallback()}

C# 4.0 OperationException:处理时出错 此请求。-->System.Security.SecurityException:安全错误。 在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult)中 异步结果)在 System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult 异步结果)在 System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)--内部异常堆栈跟踪的结束---at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](对象 源、字符串方法、IAsyncResult异步结果)位于 System.Data.Services.Client.QueryResult.EndExecute[TElement](对象 源,IAsyncResult(异步结果)位于 System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](对象 源,DataServiceContext上下文,IAsyncResult asyncResult)位于 System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult 异步结果)在 ThreatModeler.Silverlight.ProjectWindow.b_0(IAsyncResult s) 位于System.Data.Services.Client.BaseAsyncResult.HandleCompleted()处 在 System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult 异步结果)在 System.Data.Services.Client.BaseAsyncResult.c_DisplayClass1.b_0(IAsyncResult 异步结果)在 System.Net.Browser.ClientHttpWebRequest.c_DisplayClass1a.b_u18(对象 (2)在 System.Threading.QueueUserWorkItemCallback.WaitCallback\u上下文(对象 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback回调、对象状态、布尔值 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 位于System.Threading.ThreadPoolWorkQueue.Dispatch()的 System.Threading.\u ThreadPoolWaitCallback.PerformWaitCallback()},c#-4.0,.net-4.0,wcf-data-services,odata,silverlight-5.0,C# 4.0,.net 4.0,Wcf Data Services,Odata,Silverlight 5.0,这对我有用。为我效劳 选择已安装模板下的数据,然后选择XML文件。将文件命名为clientaccesspolicy.xml 为文件输入以下内容: 这对我有用。为我效劳 选择已安装模板下的数据,然后选择XML文件。将文件命名为clientaccesspolicy.xml 为文件输入以下内容: public partial class ProjectWindow : ChildWindow { XYZEntitis.XYZEntitis db = new XYZEntitis.XYZEnti

这对我有用。为我效劳

  • 选择已安装模板下的数据,然后选择XML文件。将文件命名为clientaccesspolicy.xml
  • 为文件输入以下内容:
  • 
    

    这对我有用。为我效劳

  • 选择已安装模板下的数据,然后选择XML文件。将文件命名为clientaccesspolicy.xml
  • 为文件输入以下内容:
  • 
    
    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
            }
    
        }
    
    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">
            <domain uri="http://*" />
            <domain uri="https://*" />
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>