简体   繁体   中英

Where can I find the SSIS script task PreExecute method?

In SSIS (using VS 2013 with latest SSDT) I'm returning a SQL result set to the package and iterating through it with a Foreach ADO Enumerator. In the loop I'd like to have a control flow Script Task call a WCF service.

I have read and understand the tutorial found here but, as referenced here , this tutorial is using the data flow Script Component so I can't use its PreExecute() method.

How do I override the app.config setting programmatically to avoid the problem stated in the tutorial?

using a WCF client, the normal method of configuring the WCF client from the application configuration file doesn't work well.

Edited after answer:

I ended up structuring my code like this.

    public ChannelFactory<IMyService> ChannelFactory;
    public IMyService Client;

    public void PreExecute()
    {
        //create the binding
        var binding = new BasicHttpBinding
        {
            Security =
            {
                Mode = BasicHttpSecurityMode.Message,
                Transport = {ClientCredentialType = HttpClientCredentialType.Windows}
            }
        };

        //configure the binding
        Uri myUri = new Uri(Dts.Variables["myUri"].Value.ToString());
        var endpointAddress = new EndpointAddress(myUri);
        ChannelFactory = new ChannelFactory<IMyService>(binding, endpointAddress);

        //create the channel
        Client = ChannelFactory.CreateChannel();
    }

    public void PostExecute()
    {
        //close the channel
        IClientChannel channel = (IClientChannel)Client;
        channel.Close();

        //close the ChannelFactory
        ChannelFactory.Close();

    }

    /// <summary>
    /// This method is called when this script task executes in the control flow.
    /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    /// To open Help, press F1.
    /// </summary>
    public void Main()
    {
        PreExecute();

        //TODO: code

        PostExecute();
        Dts.TaskResult = (int)ScriptResults.Success;
    }

A ScriptTask does not have a PreExecute method. You'll have to do all the instantiation and binding stuff per iteration of your loop. It's similar to what's happening in the script component example in that the setup happens once and then all the rows stream out. If you were looping over your data flow, it'd have to redo the preexecute methods per loop.

Based on the comments at the end of the article, it sounds like the code controls the configuration and there's no need to modify the app.config. WCF stuff isn't my strong suit so I can't comment on that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM