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:
- Added Microsoft.Xrm.Sdk dll's to GAC and to script references;
- Created dataflow task and two separate script tasks inside
- Created 2 package variables
crmOrganizationService
andcrmOrganizationServiceProxy
- both of type
System.Object
script task 1
andscript task 2
can read-write them
- both of type
Inside of
script task 1
:- Instantiate
OrganizationServiceProxy
andOrganizationService
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;
- Instantiate
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.