• How to Configure an SSIS Package to Access a Web Service using WCF


    This information is from:http://blogs.msdn.com/b/dbrowne/archive/2010/07/08/how-to-configure-an-ssis-package-to-access-a-web-service-using-wcf.aspx

    When you are connecting to a web service from an SSIS Script component or transform using a WCF client, the normal method of configuring the WCF client from the application configuration file doesn’t work well.  Your package will be running in some host, like dtexec.exe, and you would have to put your client config its application configuration file.  SSIS packages have their own way of consuming configuration, by either setting package variables (or other settings) from the command line, or using an external package configuration (stored in a SQL Server table or XML file).  To use the normal SSIS configuration mechanisms to configure a WCF client, the easiest way is to configure your WCF client in code, and plug in package variables for things like the service URL, or perhaps the client credentials or proxy settings.  If you configure the WCF client in code using this technique then you don't have to edit the dtexec.exe.config file.

    Here’s a quick walkthrough of calling a Web Servcie from a WCF client in an SSIS package, configuring the WCF client in code and using a package variable for the web service URL.

    First create a WCF Service for testing (or use some existing web service):

    image

    then hit F5 to run the service in the development server, and note the URL of the .svc file:

    image

    Create a new SSIS package and add a DataFlow and a Script Component configured to Source.  Add output columns to the script source to match the data flowing out of the web service.  Here it’s just a single integer.

    image

    Edit the script for the script source and change the target .NET Framework from 2.0 to 3.5 so you can use WCF:

    image

    In the Script project add a Service reference:

    image

    Enter the URL of your web service, and give it a friendly name:

    image

    Create a Package variable to configure the service URL, and give the script source read-only access to the variable.

    image

    Now edit the script to configure the WCF client in code and pass in the package variable for the URL. 

    /* Microsoft SQL Server Integration Services Script Component
    *  Write scripts using Microsoft Visual C# 2008.
    *  ScriptMain is the entry point class of the script.*/
    
    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
    using Microsoft.SqlServer.Dts.Runtime.Wrapper;
    using System.ServiceModel;
    using SC_e9f00fa5cbb748d4b5b80e10f6c61d98.csproj.MyService;
    
    
    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
    public class ScriptMain : UserComponent
    {
    
        ChannelFactory<IService1> channelFactory;
        IService1 client;
        public override void PreExecute()
        {
            base.PreExecute();
    
            //create the binding
            var binding = new WSHttpBinding();
            //configure the binding
            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    
            var endpointAddress = new EndpointAddress(this.Variables.ServiceUrl);
            channelFactory = new ChannelFactory<IService1>(binding, endpointAddress);
    
            //create the channel
            client = channelFactory.CreateChannel();
        }
    
        public override void PostExecute()
        {
            base.PostExecute();
    
            //close the channel
            IClientChannel channel = (IClientChannel)client;
            channel.Close();
    
            //close the ChannelFactory
            channelFactory.Close();
    
        }
    
        public override void CreateNewOutputRows()
        {
    
            for (int i = 0; i < 10; i++)
            {
                this.Output0Buffer.AddRow();
                CompositeType t = new CompositeType();
                t.BoolValue = false;
                t.StringValue = i.ToString();
    
                var data = client.GetDataUsingDataContract(t);
                this.Output0Buffer.id = data.BoolValue?1:0;
            }
            
        }
    
    }

    If you’re not sure what binding to use look at the app.config that the Add Service Reference wizard put in your script project.  It will tell you.  Here it requires wsHttpBinding with Message transport security and a Windows credential:

    image

    Add a simple data flow destination and test your package:

    image

    Then you can set the value of the package variable on the command line with dtexec.exe or SQL Agent, or create a package configuration that has sets them.

  • 相关阅读:
    jQuery 简单滑动轮播图效果
    西工大:同学你好,回来挂科!
    【入门】产品经理零基础怎么入门?
    【考点】 HashMap,HashTable,CurrentHashMap,LinkedHashMap,TreeMap简述
    P图鬼才们集体上线!高校毕业照P图哪家强?
    【实战】怎样实现前端裁剪上传图片功能
    校招选产品经理岗?给你浇盆水
    战胜70%对手的校招开发岗简历是这个样子的
    两个人遇到熊,装死的和转身跑的,哪个能活下来
    第一份实习工作,我应该学到什么?
  • 原文地址:https://www.cnblogs.com/vincentDr/p/3351518.html
Copyright © 2020-2023  润新知