Silverlight 4を使用したブラウザー外サービスアクセス問題4
-
29-09-2019 - |
質問
いくつかのWCFデータサービスにアクセスするSilverlight 4アプリケーションがあります。
ブラウザを介してサービスにアクセスするのに問題はありません。
私は、信頼の高まりでブラウザー外に実行するようにプログラムを設定しました。その後、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.xml
と clientaccesspolicy.xml
WebServerのルートにあるファイルですが、これらのファイルが要求されているのを見ることさえできません(Fiddler)。
何か案は?
解決
はい - あなたは問題がクロスサイトのアクセスに関連していると仮定しますが、実際にはそれはクロスに関連しています -スレッド アクセス(エラーの最初の行はこれを明確に示します)。
私は、サービスコールの処理から直接UI要素のデータバインドされた(または問題ない)プロパティを設定しようとしていると仮定しています。 (編集)明確化を忘れた - UIスレッドとは異なるスレッドでコールバックが実行されている場所。 Silverlightは、他のほとんどのフレームワークと同様に、UIスレッドを除き、UIを変更することを許可します。
もしそうなら、使用方法を見てください Dispatcher
UIスレッドに切り替えるため。
所属していません StackOverflow