CRM prompts for credentials when I add threading in Silverlight
I have a silverlight app embedded in an IFRAME in Dynamics CRM... calls after the form is loaded retrieve data via the CRM service soap client. The client is programmatically initialized with the URL and the CRM authentication token injected into the headers.
All of this, by itself, works perfectly fine.
The problem came in when I added a "loading..." animation. To display the animation correctly, I've marshalled the service requests onto a background thread, essentially replacing...
QuestionContext.RetrieveOptions();
... with ...
ThreadPool.QueueUserWorkItem(delegate {
QuestionC开发者_如何学Context.RetrieveOptions();
});
The moment I do this, though, I (somewhat sporadically) get a credentials prompt. Cancelling the prompt results in a "Not Found" error by the web service.
I've placed clientaccesspolicy.xml in the CRMWeb root, my ISV site root, as well as the ClientBin folder where my .xap is located... none of them are making a difference.
UPDATE: Providing valid credentials in the prompt has no effect, the prompt re-appears 3 times and then we're back to the "Not Found" error.
UPDATE: I've wrapped the service call responses with some error checking, each time on the "Not Found" error simply re-issuing the request. Now, pressing cancel in the credentials prompt whenever it is presented eventually results in satisfied requests. That is, it doesn't consistently fail, and re-issuing the request an unspecified number of times eventually results in success.
I've also added a Thread.Sleep() in before my Execute() call to the soap client in an effort to see if the calls were somehow interfering with one another, but it hasn't seemed to make a difference.
I was facing the exact same problem, and finally figured out how to solve it. The key is to create the CrmService client on the same thread that you call it from. I had a CrmService class that wrapped up all my interactions with the Crm Web Service, and in the CrmService ctor I created the new Crm Web Service. then I tried to use the background worker to make a call on the service. Once I moved the new Crm Web Service to the same thread as the call on the web service, it all worked fine.
精彩评论