Silverlight消耗Odata feed错误?

时间:2011-06-20 05:29:19

标签: silverlight wcf odata clientaccesspolicy.xml

我只是将Silverlight应用程序连接到我们的Odata提供者。我已经有一个使用OData提供商的IPad应用程序,所以我知道提供者没有问题。

当我尝试从OData提供程序检索数据时,我的silverlight应用程序发生了很多错误。所以这是我的代码:

Dim context As MyEntities

    context = New MyEntities(New Uri("http://localhost:8080/MyOdataProvider/OData.svc"))

    ' Initialize the binding and view source collections.
    trackedOrders = New DataServiceCollection(Of MyUser)()
    ' Define a query that returns orders for a give customer.
    Dim query = From orderByCustomer In context.MyUsers _
                    Select orderByCustomer

    ' Asynchronously load the result of the query.
    trackedOrders.LoadAsync(query)

    ' Define a handler for the LoadCompleted event of the collection.
    AddHandler trackedOrders.LoadCompleted, _
    AddressOf trackedOrders_LoadCompleted

Private Sub trackedOrders_LoadCompleted(ByVal sender As Object, _
                                    ByVal e As LoadCompletedEventArgs)
    If e.Error Is Nothing Then
        ' Load all pages of Orders before binding.
        If trackedOrders.Continuation IsNot Nothing Then
            trackedOrders.LoadNextPartialSetAsync()
        Else

            ' Bind the root StackPanel element to the collection
            ' related object binding paths are defined in the XAML.
            'ordersViewSource.Source = trackedOrders

            ' Re-enable the button since the loading is complete.
            'getCustomerOrders.IsEnabled = True
        End If
    Else
        MessageBox.Show(String.Format("An error has occured: {0}", e.Error.Message))
        '   getCustomerOrders.IsEnabled = True
    End If
End Sub

每次进入trackedOrders_LoadCompleted e.error时都会出现以下情况:


  

{System.InvalidOperationException:An   处理此错误时发生错误   请求。 --->   System.Security.SecurityException:   [Arg_SecurityException]参​​数:
  调试资源字符串是   不可用。通常是关键和   参数提供充分   诊断问题的信息。   看到   http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&File=mscorlib.dll&Key=Arg_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)
  在   System.Data.Services.Client.DataServiceRequest.EndExecute [TE   lement](对象来源,   DataServiceContext上下文,   IAsyncResult asyncResult)at   System.Data.Services.Client.DataServiceQuery 1.EndExecute(IAsyncResult asyncResult) at System.Data.Services.Client.DataServiceCollection 1&LT;&GT; C_ DisplayClass2.b _1(IAsyncResult的   asyncResult)at   System.Data.Services.Client.DataServiceCollection 1.<>c__DisplayClassd.<>c__DisplayClassf.<BeginLoadAsyncOperation>b__b()} System.InvalidOperationException: {System.InvalidOperationException: An error occurred while processing this request. ---> System.Security.SecurityException: [Arg_SecurityException] Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.60401.00&File=mscorlib.dll&Key=Arg_SecurityException at 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) --- End of inner exception stack trace --- at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult) at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.C lient.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult) at System.Data.Services.Client.DataServiceQuery
1.EndExecute(IAsyncResult的   asyncResult)at   System.Data.Services.Client.DataServiceCollection 1.<>c__DisplayClass2.<LoadAsync>b__1(IAsyncResult asyncResult) at System.Data.Services.Client.DataServiceCollection 1&LT;&GT; C_ DisplayClassd&LT;。&以及c _DisplayClassf.b__b()}


我已经从微软那里复制了这个代码怎么样和它的混蛋非常糟糕,因为我一直试图改变东西,看它是否有所作为。

我还在odata提供商wwwroot上设置了clientAccessPolicy.xml,所以我希望这不是问题所在。这是我的clientAccessPolicy文件:

 <?xml version="1.0" encoding="utf-8"?> 
 <access-policy> 
   <cross-domain-access> 
     <policy> 
       <allow-from http-request-headers="*"> 
         <domain uri="*"/> 
       </allow-from> 
       <grant-to> 
         <resource path="/" include-subpaths="true"/>
       </grant-to> 
     </policy> 
   </cross-domain-access> 
 </access-policy>

关于错误可能由什么引起的任何想法?我在这里撕扯我的头发。

0 个答案:

没有答案