Schlagwort-Archive: Dynamics CRM

OpenThreadToken failed with hr = 1008

The crm sdk includes the class CrmImpersonator which allows to execute code with the crm user credentials instead the website credentials.

If you have used this class, you may have come into situations in which the constructor has thrown an InvalidOperationException with the message OpenThreadToken failed with hr = 1008. A little research shows, that the most common reason of this exception is that the CrmImpersonator only works if your website is executed in the context of the crm.

But even if the application runs in the context of crm there is a gotcha which leads to this exception. If you use a generic handler in your application and you are creating a new instance of the CrmImpersonator in the constructor of this handler, it will throw the same exception. See this example for reference

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Handler1 : IHttpHandler, IDisposable
{
  private CrmImpersonator _impersonator;
 
  public Handler1()
  {
    _impersonator = new CrmImpersonator();
  }
 
  public void ProcessRequest(HttpContext context)
  {
    context.Response.ContentType = "text/plain";
    context.Response.Write("Hello World");
  }
 
  public bool IsReusable
  {
    get{ return false; }
  }
 
  public void Dispose()
  {
    if (_impersonator != null)
    {
       _impersonator.Dispose();
       _impersonator = null;
    }
  }
}

It seems that the thread which processes the request is not properly initialized at this point. The solution of this problem is simple. You have to create the CrmImpersonator in the ProcessRequest method of your handler.

Überarbeiten eines Angebots

Um über den Webservice eine Revision eines Angebots zu erstellen, muss dieses zuerst mit dem Status ‚Überarbeitet‘ geschlossen werden.

quoteclose qc = new quoteclose();
qc.quoteid = new Lookup( EntityName.quote.ToString(), q.quoteid  );
 
CloseQuoteRequest cqr = new CloseQuoteRequest();
cqr.QuoteClose = qc;
cqr.Status = 7;
 
service.Execute(cqr);

Danach kann eine neue Revision erzeugt werden

ReviseQuoteRequest rqr = new ReviseQuoteRequest();
 
rqr.QuoteId = quoteid;
rqr.ColumnSet = new AllColumns();
 
ReviseQuoteResponse rqresp = (ReviseQuoteResponse)service.Execute(rqr);
 
quote  quoteDraft = (quote)rqresp.BusinessEntity;

Rollup 2 für Microsoft Dynamics CRM 4 verfügbar

Microsoft hat den zweiten Rollup für CRM 4 veröffentlicht (http://www.microsoft.com/downloads/details.aspx?displaylang=de&FamilyID=aa671769-61e9-45c4-919f-c88199aa4241).

Bitte beachten: der Rollup wurde am 8.2 ein zweites Mal veröffentlicht, da die erste Version diverse Fehler enthielt (siehe http://blogs.msdn.com/crm/archive/2009/02/11/update-rollup-2-for-microsoft-dynamics-crm-4-0-more-info.aspx )