Findings on Sdk.Soap.js Action Message and Entity Class Generator

Microsoft Dynamics CRM SDK team released the Sdk.Soap.js to write JavaScript code in web resources that can perform actions using theMicrosoft Dynamics CRM 2013 Modern App SOAP endpoint. You can use this library in with web resources.
http://code.msdn.microsoft.com/SdkSoapjs-9b51b99a
The extension of the Sdk.Soap.js is Action Message Generator:
http://code.msdn.microsoft.com/SdkSoapjs-Action-Message-971be943
And Entity Class Generator:
http://code.msdn.microsoft.com/SdkSoapjs-Entity-Class-14ca830f
That really useful in creating early-binding type of development for Dynamics CRM.

I followed through the instruction for the Action Message Generator to connect to Dynamics CRM Online instance. I follow exactly each steps that the instruction described, however I got the following error:

The application terminated with an error.
The server could not be contacted.
the LDAP server is unavailable.

SoapSDKError

Initially I was quite confused with the error message, as I did not change any part of the SDK sample code at all. So, I decided to debug the code and I found out that the exception was coming from the lines that were trying to authenticate with the current UserPrincipalName with PrincipalServerDownException. The reason I got the above error is:

  1. My computer is joined to a my company’s domain, and the I’m logged in to the computer as a domain account. However, the DC is unavailable. (I’m off the domain; working on home network)
  2. I’m on the domain. However, I’m in a multiple-domain environment in which the LDAP query service is on an inaccessible domain. (firewall rules on WiFi connection).

 

So, to fix this issue I modified the sample SDK code that apparently utilising the same CrmServiceHelpers class from the Quick Start guide (http://msdn.microsoft.com/en-us/library/hh675400.aspx); from:


// For OnlineFederation environments, initially try to authenticate with the current UserPrincipalName
// for single sign-on scenario.
else if (config.EndpointType == AuthenticationProviderType.OnlineFederation
 && config.AuthFailureCount == 0
 && !String.IsNullOrWhiteSpace(UserPrincipal.Current.UserPrincipalName))
{
 config.UserPrincipalName = UserPrincipal.Current.UserPrincipalName;
 return null;
}
// Otherwise request username and password.
else
{
 config.UserPrincipalName = String.Empty;
 if (config.EndpointType == AuthenticationProviderType.LiveId)
 Console.Write("\n Enter Microsoft account: ");
 else
 Console.Write("\n Enter Username: ");
 userName = Console.ReadLine();
 if (string.IsNullOrWhiteSpace(userName))
 {
 return null;
 }

Console.Write(" Enter Password: ");
 password = ReadPassword();
}
credentials.UserName.UserName = userName;
credentials.UserName.Password = ConvertToUnsecureString(password);
break; 

To:


// For OnlineFederation environments, initially try to authenticate with the current UserPrincipalName
// for single sign-on scenario.
else
{
 var isPrincipalServerDown = false;
 var currentUserPrincipalName = String.Empty;
 try
 {
 currentUserPrincipalName = UserPrincipal.Current.UserPrincipalName;
 }
 catch (PrincipalServerDownException)
 {
 isPrincipalServerDown = true;
 }

if (config.EndpointType == AuthenticationProviderType.OnlineFederation
 && config.AuthFailureCount == 0 && !isPrincipalServerDown
 && !String.IsNullOrWhiteSpace(currentUserPrincipalName))
 {
 config.UserPrincipalName = currentUserPrincipalName;
 return null;
 }
 // Otherwise request username and password.
 else
 {
 config.UserPrincipalName = String.Empty;
 if (config.EndpointType == AuthenticationProviderType.LiveId)
 Console.Write("\n Enter Microsoft account: ");
 else
 Console.Write("\n Enter Username: ");
 userName = Console.ReadLine();
 if (string.IsNullOrWhiteSpace(userName))
 {
 return null;
 }

Console.Write(" Enter Password: ");
 password = ReadPassword();
 }
}
credentials.UserName.UserName = userName;
credentials.UserName.Password = ConvertToUnsecureString(password);
break;

Now I’m able to generate the Custom Action that generated by the tool:
Successful

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s