Random Musings

July 24, 2009

Is it possible to register different event handlers in only one assembly to be registered in Dynamics CRM Plugin ?

Filed under: Dynamics CRM — haditeo @ 9:41 am
Tags:

The answer is Yes.

plugin_registration_tool_main_window

The reason why i need this, is because i would like to register only a single DLL for the Plugin DLL, let’s called it XXX.CRM.Plugin

visual_studio_solution

To register multiple event handler, create multiple classes that implements Execute method of the IPlugin interface, then automatically when you register the plugin, you can load those classes

register_assembly

Now, the question is how do i select which class to be loaded against my event message ? When you register a new step, there is a plugin dropdownlist, you can select which class to be executed. Since we are registering two classes, then there will be two plugin options in the drop down list

select_which_plugin_to_be_executed

July 6, 2009

Create simple domain generator by reading from CRM Metadata

Filed under: c#,Dynamics CRM — haditeo @ 9:30 pm
Tags: ,

Objective
I would like to create my own domain (class) from the custom CRM entity. The advantage of this is to simplify domain persistence and retrieval between application layer and database layer (CRM Web Service)

How to achieve this ?

  • First of all we utilize RetrieveEntityRequest message to retrieve all attributes of the specific entity.
                    RetrieveEntityRequest request = new RetrieveEntityRequest();
                    request.LogicalName = entityName;
                    request.EntityItems = EntityItems.IncludeAttributes;
    
                    RetrieveEntityResponse response = (RetrieveEntityResponse)metadataService.Execute(request);
    
                    EntityMetadata entityMetadata = response.EntityMetadata;
    
                    foreach (AttributeMetadata attributeMetadata in entityMetadata.Attributes)
                    {
                        //loop through all attributes here.
                    }
    
  • There are some interesting attributes of the AttributeMetadata. Such as LogicalName attribute, DisplayName attribute and AttributeType attribute
  • By looping through each of the attributes, i read the relevant template file consisting of the code templates and replace the necessary placeholder with the actual values

    private LookupProperty _#internalVariableName#;
    [CrmAttributeMapping("#crmAttributeMapping#")]
    public LookupProperty #publicPropertyName#
    {
        get { return _#internalVariableName#; }
        set { _#internalVariableName# = value; }
    }
    
    public void Set#publicPropertyName#(Guid value)
    {
        _#internalVariableName# = new LookupProperty("#crmAttributeMapping#", new Lookup("#lookupAttributeMapping#", value));
    }
    
    public bool Is#publicPropertyName#Null()
    {
        if (_#internalVariableName# == null)
            return true;
    
        if (_#internalVariableName#.Value == null)
            return true;
    
        if (_#internalVariableName#.Value.Value == Guid.Empty)
            return true;
            
        return false;
    }
    

    Here are the result of the placeholder value replacement

    private LookupProperty _owninguser;
    [CrmAttributeMapping("owninguser")]
    public LookupProperty owninguser
    {
        get { return _owninguser; }
        set { _owninguser = value; }
    }
    
    public void Setowninguser(Guid value)
    {
        _owninguser = new LookupProperty("owninguser", new Lookup("#lookupAttributeMapping#", value));
    }
    
    public bool IsowninguserNull()
    {
        if (_owninguser == null)
            return true;
    
        if (_owninguser.Value == null)
            return true;
    
        if (_owninguser.Value.Value == Guid.Empty)
            return true;
            
        return false;
    }
    
  • Some clean up needs to be performed to tidy up the public Property name, but this code generator has helped me tremendeously to eliminate boring and repititive tasks of creating custom domain objects by hand.

June 27, 2009

what is the difference between RetrieveRequest and RetrieveMultipleRequest

Filed under: Dynamics CRM — haditeo @ 10:43 am
Tags: ,

RetrieveRequest is used to retrieve one and only one record based on the unique EntityId while RetrieveMultipleRequest can be used to retrieve one or many records based on the selection criteria.

You can use RetrieveMultipleRequest to retrieve a particular record based on EntityId, usually i create a helper method by using RetrieveMultipleRequest to retrieve particular records based on selection criteria

Here is the example of using RetrieveRequest. Our scenario is retrieving a particular account based on accountid attribute

public DynamicEntity RetrieveByUsingRetrieveRequest(CrmService service, Guid accountId)
{
    TargetRetrieveAccount target = new TargetRetrieveAccount();
    target.EntityId = accountId;

    RetrieveRequest request = new RetrieveRequest();
    request.Target = target;
    
    // retrieve all attributes of the particular account
    request.ColumnSet = new AllColumns();
    
    // tell the CRM SDK to return the result as DynamicEntity type of object
    request.ReturnDynamicEntities = true;
    RetrieveResponse response = (RetrieveResponse) service.Execute(request);
    
    DynamicEntity de = (DynamicEntity)response.BusinessEntity;
    
    return de;
}

and here is the example of using RetrieveMultipleRequest

public DynamicEntity RetrieveByUsingRetrieveMultipleRequest(CrmService service, Guid accountId)
{
    QueryExpression query = new QueryExpression();
    query.EntityName = "account";
    
    ConditionExpression ceAccount = new ConditionExpression();
    ceAccount.AttributeName = "accountid";
    ceAccount.Operator = ConditionOperator.Equal;
    ceAccount.Values = new object[] {accountId};
    
    FilterExpression feAccount = new FilterExpression();
    feAccount.AddCondition(ceAccount);
    feAccount.FilterOperator = LogicalOperator.And;
    
    query.Criteria.AddFilter(feAccount);

    // retrieve all attributes of the particular account
    query.ColumnSet = new AllColumns();

    RetrieveMultipleRequest request = new RetrieveMultipleRequest();
    request.Query = query;
    
    // tell the CRM SDK to return the result as DynamicEntity type of object
    request.ReturnDynamicEntities = true;

    RetrieveMultipleResponse response = (RetrieveMultipleResponse) service.Execute(request);

    DynamicEntity de = (DynamicEntity)response.BusinessEntityCollection.BusinessEntities[0];

    return de;
}

Note :

  • ReturnDynamicEntities property can be used to configure the CRM SDK either to return the result as Dynamic Entity or Proxy Class
  • The disadvantage of using RetrieveRequest is the query can only be implemented by querying the entity-id. Usually our goal is to obtain the particular entity-id by querying certain criteria.

    Let me elaborate further. Suppose you like to know which accounts residing in Singapore, you can query like this SELECT * FROM account where city=’Singapore’ and it will return the list of accounts complete with the account id

    It’s not useful to use RetrieveRequest, if we know ahead all accounts, means SELECT * FROM account where accountid = ‘3F2504E0-4F89-11D3-9A0C-0305E82C3301’

    Usually our targets are the Unique Identifiers.

June 25, 2009

How to: Add the CrmService Web Reference

Filed under: Dynamics CRM — haditeo @ 9:29 pm
Tags: ,

I seldom use CRM Service proxy Web Reference and i almost forgot that there is a difference in invoking the web service between CRM 3.0 and CRM 4.0

Here is the CRM 3.0 way:

http://<your server name>/mscrmservices/2006/crmservice.asmx

and here is the CRM 4.0 way:

http://<servername[:port]>/mscrmservices/2007/crmservice.asmx?WSDL&uniquename=organizationName

No wonder when i invoke using below code, i still can obtain the CrmService, but i cannot find any proxy entities there

http://<your server name>/mscrmservices/2007/crmservice.asmx

After i using the correct way, i can refer to the CRM entities through intellisense as usual
class_account

intellisense

I forgot that in the CRM 4.0, there is a multitenancy concept, so we can create multiple organization within one Dynamics CRM deployment, so to refer to the particular organization CRM entities, we can customize the organization name below

http://<servername[:port]>/mscrmservices/2007/crmservice.asmx?WSDL&uniquename=organizationName

Type.GetType() return null value

Filed under: Dynamics CRM — haditeo @ 9:06 pm

Here are my code snippet that returning null value when invoking Type.GetType()

        public Opportunity ToOpportunity(DynamicEntity de)
        {
            try
            {
                Assembly sdkDll = Assembly.LoadFrom("microsoft.crm.sdk.dll");

                Opportunity newOpportunity = new Opportunity();

                foreach (PropertyInfo pi in typeof(Opportunity).GetProperties())
                {
                    string crmFieldMapping = ((CrmFieldMapping)(pi.GetCustomAttributes(typeof(CrmFieldMapping), false))[0]).GetCrmFieldMapping();
                    string crmTypeProperty = ((CrmTypeProperty)(pi.GetCustomAttributes(typeof(CrmTypeProperty), false))[0]).GetCrmTypeProperty();

                    if (de.Properties.Contains(crmFieldMapping))
                    {
                        Type currentCrmTypeProperty = sdkDll.GetType("Microsoft.Crm.Sdk." + crmTypeProperty);

                        object obj = Activator.CreateInstance(currentCrmTypeProperty, crmFieldMapping, de[crmFieldMapping]);

                        pi.SetValue(newOpportunity, obj, null);
                    }
                }

                return newOpportunity;
            }
            catch (SoapException soapExc)
            {
                throw soapExc;
            }
            catch (Exception exc)
            {
                throw exc;
            }

        }

The above codes are working well when i have tested by testing the dll using NUnit. But when i deployed it as a custom workflow activity, these code snippet returned null value. There is an IOException complained by the system. In the details of the Exception, it’s mentioned that it cannot find the microsoft.crm.sdk.dll at the ‘c:\windows\system32’. I have tried to copy the code manually to \windows\system32 but it still cannot find the correct dll, maybe i should register it through the GAC.

Type currentCrmTypeProperty = sdkDll.GetType("Microsoft.Crm.Sdk." + crmTypeProperty);

Anyway, i have another alternative by directly using Type.GetType as shown below. I was reluctant to use the Full Assembly Qualified Name, but somehow when referring to microsoft.crm.sdk.KeyProperty, it still cannot find, unless i specified Full Qualified Name

 Type currentCrmTypeProperty = Type.GetType("Microsoft.Crm.Sdk." + crmTypeProperty + ", Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); 

And here are the modified code

        public Opportunity ToOpportunity(DynamicEntity de)
        {
            try
            {
                Opportunity newOpportunity = new Opportunity();

                foreach (PropertyInfo pi in typeof(Opportunity).GetProperties())
                {
                    string crmFieldMapping = ((CrmFieldMapping)(pi.GetCustomAttributes(typeof(CrmFieldMapping), false))[0]).GetCrmFieldMapping();
                    string crmTypeProperty = ((CrmTypeProperty)(pi.GetCustomAttributes(typeof(CrmTypeProperty), false))[0]).GetCrmTypeProperty();

                    if (de.Properties.Contains(crmFieldMapping))
                    {
                        Type currentCrmTypeProperty = Type.GetType("Microsoft.Crm.Sdk." + crmTypeProperty + ", Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); 
                                                 
                        object obj = Activator.CreateInstance(currentCrmTypeProperty, crmFieldMapping, de[crmFieldMapping]);

                        pi.SetValue(newOpportunity, obj, null);
                    }
                }

                return newOpportunity;
            }
            catch (SoapException soapExc)
            {
                throw soapExc;
            }
            catch (Exception exc)
            {
                throw exc;
            }

        }

June 21, 2009

Using reflection to iterate over all the properties inside an object

Filed under: Dynamics CRM — haditeo @ 6:04 pm
Tags: ,

Here are the code snippet before it’s refactored using reflection :

        public DynamicEntity Convert(Project newProject)
        {
            try
            {
                DynamicEntity deProject = new DynamicEntity();
                deProject.Name = "new_project";


                if (newProject.IsProjectRefExist())
                    deProject.Properties.Add(newProject.ProjectRef);

                if (newProject.IsClientExist())
                    deProject.Properties.Add(newProject.Client);

                if (newProject.IsPrimaryContactExist())
                    deProject.Properties.Add(newProject.PrimaryContact);

                if (newProject.IsClientCategoryExist())
                    deProject.Properties.Add(newProject.ClientCategory);

                if (newProject.IsProjectTitleExist())
                    deProject.Properties.Add(newProject.ProjectTitle);

                if (newProject.IsProjectTitleInChineseExist())
                    deProject.Properties.Add(newProject.ProjectTitleInChinese);

                if (newProject.IsAccountManagerExist())
                    deProject.Properties.Add(newProject.AccountManager);

                if (newProject.IsKbaExist())
                    deProject.Properties.Add(newProject.Kba);

                if (newProject.IsServiceTypeExist())
                    deProject.Properties.Add(newProject.ServiceType);

                if (newProject.IsDevelopmentTypeExist())
                    deProject.Properties.Add(newProject.DevelopmentType);

                if (newProject.IsRegionExist())
                    deProject.Properties.Add(newProject.Region);

                if (newProject.IsLocationExist())
                    deProject.Properties.Add(newProject.Location);

                if (newProject.IsCountryExist())
                    deProject.Properties.Add(newProject.Country);

                if (newProject.IsDescriptionExist())
                    deProject.Properties.Add(newProject.Description);

                if (newProject.IsSourceExist())
                    deProject.Properties.Add(newProject.Source);

                if (newProject.IsEstimatedProjectCostExist())
                    deProject.Properties.Add(newProject.EstimatedProjectCost);

                if (newProject.IsEstimatedProjectFeesExist())
                    deProject.Properties.Add(newProject.EstimatedProjectFees);

                if (newProject.IsEstimatedFeesPercentageExist())
                    deProject.Properties.Add(newProject.EstimatedFeesPercentage);

                if (newProject.IsEstimatedProjectStartDateExist())
                    deProject.Properties.Add(newProject.EstimatedProjectStartDate);

                if (newProject.IsEstimatedProjectEndDateExist())
                    deProject.Properties.Add(newProject.EstimatedProjectEndDate);

                return deProject;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

and here are the code after it’s refactored

        public DynamicEntity Convert(Project newProject)
        {
            try
            {
                DynamicEntity deProject = new DynamicEntity();
                deProject.Name = "new_project";

                foreach (PropertyInfo projectProperty in typeof(Project).GetProperties())
                {
                    // skip if the method is not exist
                    if ((typeof(Project).GetMethod("Is" + projectProperty.Name + "Exist")) == null)
                        continue;

                    bool isPropertyHasValue = (bool)(typeof(Project).GetMethod("Is" + projectProperty.Name + "Exist")).Invoke(newProject, null);

                    //don't add to the Project's dynamic entity with the null value of the current Project property
                    if (!isPropertyHasValue)
                        continue;

                    deProject.Properties.Add((Property)projectProperty.GetValue(newProject, null));
                }

                return deProject;
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

Reflection is cool. What reflection techniques that i am using it here ?

  • I am using these code snippet to iterate to all the properties inside an object. The advantage of this is i do not need to hard code additional lines when my business object gets added with additional attributes
    foreach(PropertyInfo projectProperty in typeof(Project).GetProperties())
    {}
    
  • I am using the GetMethod() to check whether a particular method name is indeed exist inside the object
    if ((typeof(Project).GetMethod("Is" + projectProperty.Name + "Exist")) == null)
    
  • I am using the Invoke() to invoke the particular method. Fortunately i do not need to pass the parameter
    (bool)(typeof(Project).GetMethod("Is" + projectProperty.Name + "Exist")).Invoke(newProject, null);
    
  • As usual, i always use the GetValue method to obtain the current property value for the particular object

    (Property)projectProperty.GetValue(newProject, null)
    

June 19, 2009

Reflection in C#

Filed under: Dynamics CRM — haditeo @ 10:00 pm
Tags: , ,

These are the code before it’s refactored

         private Opportunity ToOpportunity(DynamicEntity de)
         {
             try
             {
                 Opportunity opportunity = new Opportunity();

                 foreach (string attribute in opportunity.AttributesList)
                 {
                     if (!de.Properties.Contains("opportunityid"))
                         throw new PropertiesNotExistException("The Dynamic Entity type Opportunity does not have id property");

                     opportunity.Id = new KeyProperty("opportunityid", ((Key)de["opportunityid"]));

                     switch (attribute)
                     {
                         case "customerid":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetPotentialClient(((Customer)de[attribute]).Value);
                             break;
                         case "new_contactpersonid":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetContactPerson(((Lookup)de[attribute]).Value);
                             break;
                         case "new_clientcategory":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetClientCategory(((Picklist)de[attribute]).Value);
                             break;
                         case "name":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetPotentialProjectTitle(de[attribute].ToString());
                             break;
                         case "new_potentialprojecttitlechinese":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetPotentialProjectTitleInChinese(de[attribute].ToString());
                             break;
                         case "new_accountmanager":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetAccountManager(de[attribute].ToString());
                             break;
                         case "new_kba":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetKba(((Picklist)de[attribute]).Value);
                             break;
                         case "new_servicetype":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetServiceType(((Picklist)de[attribute]).Value);
                             break;
                         case "new_developmenttype":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetProjectDevelopmentType(((Picklist)de[attribute]).Value);
                             break;
                         case "new_regionopportunityid":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetRegion(((Lookup)de[attribute]).Value);
                             break;
                         case "new_location":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetLocation(de[attribute].ToString());
                             break;
                         case "new_countryopportunityid":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetCountry(((Lookup)de[attribute]).Value);
                             break;
                         case "description":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetDescription(de[attribute].ToString());
                             break;
                         case "new_source":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetSource(((Picklist)de[attribute]).Value);
                             break;
                         case "new_estimatedprojectcost":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetEstimatedProjectCost(((CrmMoney)de[attribute]).Value);
                             break;
                         case "estimatedvalue":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetEstimatedProjectFees(((CrmMoney)de[attribute]).Value);
                             break;
                         case "new_estimatedfeespercentage":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetEstimatedFeesPercentage(((CrmDecimal)de[attribute]).Value);
                             break;
                         case "new_estimatedprojectstartdate":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetEstimatedProjectStartDate(((CrmDateTime)de[attribute]).UserTime);
                             break;
                         case "new_estimatedprojectenddate":
                             if (de.Properties.Contains(attribute))
                                 opportunity.SetEstimatedProjectEndDate(((CrmDateTime)de[attribute]).UserTime);
                             break;
                     }
                 }
                 return opportunity;
             }
             catch (SoapException soapExc)
             {
                 throw soapExc;
             }
             catch (Exception exc)
             {
                 throw exc;
             }

         }

and these are the code after it’s refactored

        public Opportunity ToOpportunity(DynamicEntity de)
        {
            try
            {
                Assembly sdkDll = Assembly.LoadFrom("microsoft.crm.sdk.dll");

                Opportunity newOpportunity = new Opportunity();

                foreach(PropertyInfo pi in  typeof(Opportunity).GetProperties())
                {
                    string crmFieldMapping = ((CrmFieldMapping)(pi.GetCustomAttributes(typeof(CrmFieldMapping), false))[0]).GetCrmFieldMapping();
                    string crmTypeProperty = ((CrmTypeProperty)(pi.GetCustomAttributes(typeof(CrmTypeProperty), false))[0]).GetCrmTypeProperty();

                    if (de.Properties.Contains(crmFieldMapping))
                    {
                        Type currentCrmTypeProperty = sdkDll.GetType("Microsoft.Crm.Sdk." + crmTypeProperty);

                        object obj = Activator.CreateInstance(currentCrmTypeProperty, crmFieldMapping, de[crmFieldMapping]);

                        pi.SetValue(newOpportunity, obj, null);
                    }
                }

                return newOpportunity;
            }
            catch (SoapException soapExc)
            {
                throw soapExc;
            }
            catch (Exception exc)
            {
                throw exc;
            }

        }

Currently i’m closely applying Domain Driven Development by creating domain objects first. The previous source code is created without using reflection. Yesterday, i was wondering and got the idea of decorating the domain object with custom attributes as metadata, so that i can easily refer to it when reflecting the object at runtime.

These are the sample of the custom attribute :

    public class Opportunity
    {
        private KeyProperty opportunityId;
        [CrmTypeProperty("KeyProperty")]
        [CrmFieldMapping("opportunityid")]
        public KeyProperty Id
        {
            get { return opportunityId; }
            set { opportunityId = value; }
        }

        private StringProperty _projectTitle;
        [CrmTypeProperty("StringProperty")]
        [CrmFieldMapping("name")]
        public StringProperty PotentialProjectTitle
        {
            get { return _projectTitle; }
            set { _projectTitle = value; }
        }
   }

What are the advantages of using reflection ? Now, let’s say i am adding another property at the domain object, i just need to update the domain object and i don’t need to change the code at the data layer.

June 18, 2009

ILMerge : A tool to merge your multiple assemblies into one assembly

Filed under: Dynamics CRM — haditeo @ 11:48 pm
Tags:

This ILMerge has rescued me once more.

I was developing a Dynamics CRM Custom Workflow activity. As usual, the assembly needs to be signed correctly and there is one problem though. Only one assembly can be registered using the Plugin Registration Tool.

Currently i like to have a minimum 4 assemblies in my custom solution. Here are they :
1) Domain
2) Repository
3) Utilities or Helper
4) Either web, workflow or plugin dll anything
5) Usually i have a test library to be tested using NUnit

The ILMerge has a GUI tool to automate the merging of all your assemblies, but you can still use the command line. Anyway the GUI tool will execute the ILMerge command line to merge your assemblies

Here is the sample of using ILMerge

ILMerge /t:library /out:CustomLibrary.dll DomainLibrary.dll RepositoryLibrary.dll Utilities.dll Workflow.dll

/t option means we are emitting a dll library. We can also emit an executable file
/out option means we are specifying CustomLibrary.dll as the name of the one dll to be produced by the ILMerge
All the libraries that we would like to be merged should be specified individually with the space between them

June 16, 2009

Error 401 while using NetworkCredential

Filed under: Dynamics CRM — haditeo @ 10:02 am

While running these code snippet to invoke Dynamics CRM Web Service using NetworkCredential, i have encountered the famous HTTP Error 401.2 – Unauthorized Access is Denied

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "123";

CrmService service = new CrmService();
service.Url = "http://SERVER123/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;

NetworkCredential nc = new NetworkCredential();
nc.Domain = "STAFF";
nc.UserName = "Administrator";
nc.Password = "whatisthepassword";

service.Credentials = nc;

Fiddler

Notice the current domain name. It’s specified as “STAFF.COM”, but inside the code above, i have specified it as “STAFF”. After i changed it to “STAFF.COM”, it’s working well at the 1st HTTP request. In my assumption, i don’t need to include Full Qualified Domain Name (FQDN), but eventually the system must accept a FQDN

AD

Here are the things that i have tried before i found the current solution:

  • Downloaded Authentication Diagnostic to help pointing whether the current user (STAFF\Administrator) has proper rights and privileges to the current server.

    Found out that the current Dynamics CRM application pool is run with NetworkService user account, it needs to be changed to run under a valid user account.

  • Setspn command is also used to create SPN for the current user (STAFF\Administrator) to be authenticated properly in the current user
  • Tried to use DefaultCredentials and DefaultNetworkCredentials, turned out that it’s working well.

    service.Credentials = CredentialCache.DefaultCredentials;
    
    service.Credentials = CredentialCache.DefaultNetworkCredentials;
    

    At this point, i am very confuse, why it’s working on DefaultNetworkCredentials , and found out the domain name that i have specified is incorrect.

June 15, 2009

Open thread token failed error message

Filed under: Dynamics CRM — haditeo @ 9:57 pm
Tags: ,

While i was using ExtractCrmAuthenticationToken method, i have encountered this error message “Open thread token failed with hr = 1008” while running the solution. The compilation is working well.

OpenThreadToken

Why the error message is appeared ?
1) I placed the .ASPX custom solution outside of Dynamics CRM website.
2) In order to extract CRM authentication token, the custom solution must be placed under the Dynamics CRM website so that it can extract the authentication token which is utilized by CRM in the web.config . Here is the web.config definition taken from Dynamics CRM solution

<httpModules>
    <add name ="MapOrg" type="Microsoft.Crm.MapOrgEngine, Microsoft.Crm, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add name ="CrmAuthentication" type="Microsoft.Crm.Authentication.AuthenticationEngine, Microsoft.Crm, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

The solution is :
1) Place the custom ASPX solution under the Dynamics CRM website in order to utilize the ExtractCrmAuthenticationToken method, so that this method can use the CrmAuthentication module.

Next Page »

Blog at WordPress.com.