/// <summary> /// This method is a run-time method executed dtsexec.exe /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <param name="transaction"></param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refire = false; componentEvents.FireInformation(0, "SSISWebServiceTask", "Prepare variables", string.Empty, 0, ref refire); GetNeededVariables(variableDispenser, componentEvents); try { componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("Initialize WebService: {0}", EvaluateExpression(ServiceUrl, variableDispenser)), string.Empty, 0, ref refire); object[] result; using (var wsdlHandler = new WSDLHandler(new Uri(EvaluateExpression(ServiceUrl, variableDispenser).ToString()))) { componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("InvokeRemoteMethod: {0}=>{1}", EvaluateExpression(Service, variableDispenser), EvaluateExpression(WebMethod, variableDispenser)), string.Empty, 0, ref refire); result = wsdlHandler.InvokeRemoteMethod <object>(EvaluateExpression(Service, variableDispenser).ToString(), EvaluateExpression(WebMethod, variableDispenser).ToString(), (from parameters in ((MappingParams)MappingParams) select EvaluateExpression(parameters.Value, variableDispenser)).ToArray()); } if (result != null) { if (IsValueReturned == "1") { componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("Get the Returned Value to: {0}", ReturnedValue), string.Empty, 0, ref refire); string val = ReturnedValue.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("Get the Returned Value to {0} and convert to {1}", val.Substring(0, val.Length - 1), _vars[val.Substring(0, val.Length - 1)].DataType), string.Empty, 0, ref refire); _vars[val.Substring(0, val.Length - 1)].Value = Convert.ChangeType(result[0], _vars[val.Substring(0, val.Length - 1)].DataType); componentEvents.FireInformation(0, "SSISWebServiceTask", string.Format("The String Result is {0} ", _vars[val.Substring(0, val.Length - 1)].Value), string.Empty, 0, ref refire); } else { componentEvents.FireInformation(0, "SSISWebServiceTask", "Execution without return or no associated return variable", string.Empty, 0, ref refire); } } } catch (Exception ex) { componentEvents.FireError(0, "SSISWebServiceTask", string.Format("Problem: {0}", ex.Message + "\n" + ex.StackTrace), "", 0); } finally { if (_vars.Locked) { _vars.Unlock(); } } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }
/// <summary> /// This method is a run-time method executed dtsexec.exe /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <param name="transaction"></param> /// <returns></returns> public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction) { bool refire = false; componentEvents.FireInformation(0, "SSISWCFTask", "Prepare variables", string.Empty, 0, ref refire); GetNeededVariables(variableDispenser, componentEvents); try { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Initialize the WCF Service: {0}", EvaluateExpression(ServiceUrl, variableDispenser)), string.Empty, 0, ref refire); var dynamicProxyFactory = new DynamicProxyFactory(EvaluateExpression(ServiceUrl, variableDispenser).ToString()); int count = 0; foreach (ServiceEndpoint endpoint in dynamicProxyFactory.Endpoints.Where(endPoint => endPoint.Contract.Name == EvaluateExpression(ServiceContract, variableDispenser).ToString())) { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Service Endpoint[{0}]", count++), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Address: {0}", endpoint.Address), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Contract: {0}", endpoint.Contract.Name), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Binding: {0}", endpoint.Binding.Name), string.Empty, 0, ref refire); } componentEvents.FireInformation(0, "SSISWCFTask", string.Format("InvokeRemoteMethod: {0} => {1}", EvaluateExpression(ServiceContract, variableDispenser), EvaluateExpression(OperationContract, variableDispenser)), string.Empty, 0, ref refire); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Creating DynamicProxy to {0} ServiceContract", EvaluateExpression(ServiceContract, variableDispenser)), string.Empty, 0, ref refire); DynamicProxy dynamicProxy = dynamicProxyFactory.CreateProxy(EvaluateExpression(ServiceContract, variableDispenser).ToString()); if (dynamicProxy == null) { throw new Exception("Cannot create the proxy"); } object result = null; componentEvents.FireInformation(0, "SSISWCFTask", "Creating the Client Channel", string.Empty, 0, ref refire); using (IClientChannel innerChannel = dynamicProxy.GetProperty("InnerChannel") as IClientChannel) { if (innerChannel != null) { using (new OperationContextScope(innerChannel)) { componentEvents.FireInformation(0, "SSISWCFTask", "Creating the Message Header", string.Empty, 0, ref refire); OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("SSISDynamicWCF", "", Guid.NewGuid().ToString())); componentEvents.FireInformation(0, "SSISWCFTask", "The used headers:", string.Empty, 0, ref refire); foreach (var header in ((MappingHeaders)MappingHeaders)) { var headerValue = Convert.ChangeType(EvaluateExpression(header.Value, variableDispenser).ToString(), Type.GetType(header.Type)); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Name: {0} | Type: {1} | Value: {2}", header.Name, header.Type, headerValue), string.Empty, 0, ref refire); OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader(header.Name, "", headerValue)); } componentEvents.FireInformation(0, "SSISWCFTask", "The used params:", string.Empty, 0, ref refire); foreach (var param in ((MappingParams)MappingParams)) { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Name: {0} | Type: {1} | Value: {2}", param.Name, param.Type, Convert.ChangeType(EvaluateExpression(param.Value, variableDispenser).ToString(), Type.GetType(param.Type))), string.Empty, 0, ref refire); } componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Call [{0}] OperationContract with parameters:", EvaluateExpression(OperationContract, variableDispenser)), string.Empty, 0, ref refire); int countParam = ((MappingParams)MappingParams).Count; var objParams = new object[countParam]; for (int i = 0; i < countParam; i++) { objParams[i] = Convert.ChangeType(EvaluateExpression(((MappingParams)MappingParams)[i].Value, variableDispenser).ToString(), Type.GetType(((MappingParams)MappingParams)[i].Type)); } result = dynamicProxy.CallMethod(EvaluateExpression(OperationContract, variableDispenser).ToString(), objParams); //new object[] // { // (from parameters in ((MappingParams)MappingParams) // select Convert.ChangeType(EvaluateExpression(parameters.Value, variableDispenser).ToString(), Type.GetType(parameters.Type))).ToArray() // }); } } else { componentEvents.FireInformation(0, "SSISWCFTask", "Cannot create the Inner Channel", string.Empty, 0, ref refire); throw new Exception("Cannot Create the Inner Channel"); } } if (result != null) { if (IsValueReturned == Keys.TRUE) { componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Get the Returned Value to: {0}", ReturnedValue), string.Empty, 0, ref refire); string val = ReturnedValue.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("Get the Returned Value to {0} and convert to {1}", val.Substring(0, val.Length - 1), _vars[val.Substring(0, val.Length - 1)].DataType), string.Empty, 0, ref refire); _vars[val.Substring(0, val.Length - 1)].Value = Convert.ChangeType(result, _vars[val.Substring(0, val.Length - 1)].DataType); componentEvents.FireInformation(0, "SSISWCFTask", string.Format("The String Result is {0} ", _vars[val.Substring(0, val.Length - 1)].Value), string.Empty, 0, ref refire); } else { componentEvents.FireInformation(0, "SSISWCFTask", "Execution without return or no associated return variable", string.Empty, 0, ref refire); } } } catch (Exception ex) { componentEvents.FireError(0, "SSISWCFTask", string.Format("Problem: {0}", ex.Message + "\n" + ex.StackTrace), "", 0); } finally { if (_vars.Locked) { _vars.Unlock(); } } return(base.Execute(connections, variableDispenser, componentEvents, log, transaction)); }