2

Prerequisites:

I want to connect to MS Dynamics CRM web services at the beginning of package execution and reuse the connection all over the package, but I failed to do that via SSIS Variables.

I can't use Connection manager because i use OrganizationService.Execute method that is not supported by WebService Task wizard

Steps:

  1. Added Microsoft.Xrm.Sdk dll's to GAC and to script references;
  2. Created dataflow task and two separate script tasks inside
  3. Created 2 package variables crmOrganizationService and crmOrganizationServiceProxy
    • both of type System.Object
    • script task 1 and script task 2 can read-write them
  4. Inside of script task 1:

    • Instantiate OrganizationServiceProxy and OrganizationService and connect to MS Dynamics CRM Web services.
    • Assign both instances of objects to variables

      //create public OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(orgServiceManagement, adCredentials); public IOrganizationService _service =(IOrganizationService)_serviceProxy; //assign this.Variables.crmOrganizationServiceProxy= _serviceProxy; this.Variables.crmOrganizationService=_service;

  5. Inside of script task 2:

    OrganizationServiceProxy _serviceProxy = (OrganizationServiceProxy)this.Variables.crmOrganizationServiceProxy

Error:

At step 5 I receive Invalid cast exception because of inability to cast System.Object as Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy

Workaround:

I'm sure the problem is in basic boxing of variables while passing them between script tasks. Yet I didn't find a better general approach. Within it, I need to pass instances of custom classes between script-tasks.

Quodnon
  • 43
  • 5

1 Answers1

1

You could use Reflection or a custom SSIS component but maybe doing that is not worth it.

The other option would be to host an interim web service between your SSIS package and CRM, and cache the connection in the webservice. Maybe that's a lot easier for you.

Community
  • 1
  • 1
Jordi
  • 1,460
  • 9
  • 9