使用 Silverlight 4 的浏览器外服务访问问题

发布于 2024-10-04 19:12:07 字数 2360 浏览 7 评论 0原文

我有一个 Silverlight 4 应用程序,可以访问几个 WCF 数据服务。

通过浏览器访问该服务没有问题。

我将程序设置为以更高的信任度在浏览器外运行。然后我可以通过 fiddler 查看对 WCF 服务的调用,但没有任何返回。

如果我进行调试,则会收到以下错误:

$exception  {System.UnauthorizedAccessException: Invalid cross-thread access.
   at MS.Internal.XcpImports.CheckThread()
   at System.Windows.Controls.ItemCollection.GetValueInternal(DependencyProperty dp)
   at System.Windows.PresentationFrameworkCollection`1.get_CountImpl()
   at System.Windows.PresentationFrameworkCollection`1.get_Count()
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.RemoveAll()
   at System.Windows.Controls.ItemContainerGenerator.RemoveAll()
   at System.Windows.Controls.ItemContainerGenerator.OnRefresh()
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Windows.Controls.ItemCollection.NotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Windows.Controls.ItemCollection.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
   at System.Collections.ObjectModel.Collection`1.Clear()
   at ClientFolderExplorer.ViewModels.DocumentExplorerViewModel.clientCatalog_ClientsLoadingComplete(Object sender, ClientLoadingEventArgs e)
   at ClientFolderExplorer.Catalogs.ClientCatalog.<>c__DisplayClass3.<ExecuteClientQuery>b__2(IAsyncResult a)}  System.Exception {System.UnauthorizedAccessException}

不确定从哪里开始故障排除。我在网络服务器的根目录中有 crossdomain.xmlclientaccesspolicy.xml 文件,但我什至看不到正在请求的这些文件(在 fiddler 中)。

有什么想法吗?

I have a Silverlight 4 application that access a couple of WCF Data Services.

There are no problems accessing the service through the browser.

I set the program to run out-of-browser with elevated trust. Then I can see the calls to the WCF Service via fiddler, but nothing ever comes back.

If I debug then I get the following error:

$exception  {System.UnauthorizedAccessException: Invalid cross-thread access.
   at MS.Internal.XcpImports.CheckThread()
   at System.Windows.Controls.ItemCollection.GetValueInternal(DependencyProperty dp)
   at System.Windows.PresentationFrameworkCollection`1.get_CountImpl()
   at System.Windows.PresentationFrameworkCollection`1.get_Count()
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.RemoveAll()
   at System.Windows.Controls.ItemContainerGenerator.RemoveAll()
   at System.Windows.Controls.ItemContainerGenerator.OnRefresh()
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Windows.Controls.ItemCollection.NotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Windows.Controls.ItemCollection.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
   at System.Collections.ObjectModel.Collection`1.Clear()
   at ClientFolderExplorer.ViewModels.DocumentExplorerViewModel.clientCatalog_ClientsLoadingComplete(Object sender, ClientLoadingEventArgs e)
   at ClientFolderExplorer.Catalogs.ClientCatalog.<>c__DisplayClass3.<ExecuteClientQuery>b__2(IAsyncResult a)}  System.Exception {System.UnauthorizedAccessException}

Not sure where to start troubleshooting. I have crossdomain.xml and clientaccesspolicy.xml files in place in the root of the webserver, but I cannot even see these files being requested (in fiddler).

Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄风 2024-10-11 19:12:08

是的 - 您认为问题与跨站点访问有关,而实际上它与跨线程访问有关(第一行错误清楚地表明了这一点)。

我假设您正在尝试直接从处理服务调用的回调中设置某些 UI 元素的数据绑定(或不设置,无关紧要)属性。 (编辑)忘记澄清 - 回调在与 UI 线程不同的线程上运行。与大多数其他框架一样,Silverlight 不允许修改 UI,除非从 UI 线程修改。

如果是这样,请查看如何使用 Dispatcher 来切换回 UI 线程。

Yes - you suppose the problem is related to cross-site access, while in reality it's related to cross-thread access (first line of error indicates this clearly).

I'm assuming you're trying to set some UI element's data bound (or not, doesn't matter) property directly from the callback handling the service call. (edit) Forgot to clarify - where the callback is running on a thread different from the UI thread. Silverlight like most other frameworks disallows modifying UI except from the UI thread.

If so, take a look at how to use Dispatcher in order to switch back to the UI thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文