码迷,mamicode.com
首页 > Web开发 > 详细

微软 BI ssis 中的 script task中用代码直接调用 WCF / Webservice

时间:2014-12-04 20:03:37      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   sp   strong   on   文件   

背景:

在普通的C#项目中,可以直接调用 WCF / Webservice;

在微软BI的 ssis中,有 webservice任务组件,也可以直接调用简单的 WCF / Webservice;

偶这边的情况是,后端的 WCF中用的反射,所以在 ssis中的webservice任务组件中,死活不能识别 WCF对应的方法。

所以只能在ssis的 script task组件中,用纯代码的方式来调用WCF服务。


就这样,可能还是有问题;可能会碰到 不能识别 System.ServiceModel节点的错误。根本原因在于 微软的ssis的script task组件中,它不能识别 WCF/ webservice的 app.config文件。


解决方法:除了添加服务引用外,还需要在代码中设置所有的属性,包括 URL


参考代码:

  //HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
            HttpTransportBindingElement httpsTransport = new HttpTransportBindingElement();
            httpsTransport.ManualAddressing = false;
            httpsTransport.MaxBufferPoolSize = 524288;
            httpsTransport.MaxReceivedMessageSize = 65536;
            httpsTransport.AllowCookies = false;
            httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
            httpsTransport.BypassProxyOnLocal = false;
            httpsTransport.DecompressionEnabled = true;
            httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            httpsTransport.KeepAliveEnabled = true;
            httpsTransport.MaxBufferSize = 65536;
            httpsTransport.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
            httpsTransport.Realm = "";
            httpsTransport.TransferMode = TransferMode.Buffered;
            httpsTransport.UnsafeConnectionNtlmAuthentication = false;
            httpsTransport.UseDefaultWebProxy = true;
            //httpsTransport.RequireClientCertificate = false;


            TextMessageEncodingBindingElement encoding = new TextMessageEncodingBindingElement();
            encoding.MessageVersion = MessageVersion.Soap11;
            encoding.WriteEncoding = Encoding.UTF8;
            encoding.MaxReadPoolSize = 64;
            encoding.MaxWritePoolSize = 16;
            encoding.ReaderQuotas.MaxDepth = 32;
            encoding.ReaderQuotas.MaxStringContentLength = 8192;
            encoding.ReaderQuotas.MaxArrayLength = 16384;
            encoding.ReaderQuotas.MaxBytesPerRead = 4096;
            encoding.ReaderQuotas.MaxNameTableCharCount = 16384;

            CustomBinding binding = new CustomBinding();
            binding.Name = "GetData";
            binding.Elements.Add(encoding);
            binding.Elements.Add(httpsTransport);

            EndpointAddress endPoint = new EndpointAddress("http://192.168.4.16:83/Service1.svc");

            TestServiceRef.Service1Client svc = new TestServiceRef.Service1Client(binding, endPoint);
            string sResult= svc.GetData(89);

结果:

bubuko.com,布布扣

微软 BI ssis 中的 script task中用代码直接调用 WCF / Webservice

标签:blog   http   io   ar   os   sp   strong   on   文件   

原文地址:http://blog.csdn.net/keenweiwei/article/details/41727801

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!