2
votes

Getting an unexpected error when trying to connect to CRM 2011 web service. Here's the background:

Connection String (with sensitive info removed): "ServiceUri=https://crmdomain.com/OrgName/XRMServices/2011/Organization.svc; Url=https://crmdomain.com/OrgName; Username=appusername; Password=hidden"/>

Creating the connection as follows:

  1. Parse conn string into CRMConnection: var conn = Microsoft.Xrm.Client.CrmConnection.Parse(connString); (at this point, the properties in the CrmConnection object look correct, including ClientCredentials)
  2. Create org proxy: var orgProxy = new OrganizationServiceProxy(conn.ServiceUri, conn.HomeRealmUri, conn.ClientCredentials, conn.DeviceCredentials);
  3. Create data context: var context = new MyContext(orgProxy);

At this point, when retrieving any data from context, the following WCF exception occurs:

System.ServiceModel.Security.SecurityNegotiationException occurred Message=The caller was not authenticated by the service. Source=mscorlib StackTrace: Server stack trace: at System.ServiceModel.Security.IssuanceTokenProviderBase'1.DoNegotiation(TimeSpan timeout) at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)

... and so on.

The InnerException shows IsSenderFault=True and IsPredefinedFault=True.

What's going on here?

2
Does this still fail if you use the ServerConnection helper class to build the connection string?Josh

2 Answers

0
votes

I found the solution. First of all please download the RTW release of CRM SDK 2011.

Code for connectivity will be :

public static IOrganizationService Service() 
{
    ClientCredentials Credentials = new ClientCredentials(); 
    Credentials.Windows.ClientCredential.UserName ="<username>"; 
    Credentials.Windows.ClientCredential.Password ="<password>"; 

    //This URL needs to be updated to match the servername and Organization for the environment.
    Uri OrganizationUri = new Uri("http://<server name>/<organization name>/XRMServices/2011/Organization.svc"); 
    Uri HomeRealmUri = null; 

    //OrganizationServiceProxy serviceProxy; 
    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)) 
    {
        IOrganizationService service = (IOrganizationService)serviceProxy; 
        return service; 
    }
}

and here you go...

Cheers! Enjoy coding.

0
votes

You might want to narrow down the exact error in CRM by using the CRM trace. You can activate the CRM trace with a dedicated tool and search it for more detailed information about the source of the exception. Note that the trace files get very big very fast, so it is reasonable to trace only during the webservice call.