将SSIS Web服务任务连接到Spring Web Service

时间:2012-12-04 16:59:17

标签: ssis wireshark spring-ws

我有一个SSIS包,其中我使用WebService任务来调用Spring WS。 身份验证由客户端证书和用户名&密码。

我试图像这样做一个简单的HttpConnection和一个WebService任务 - 错误504网关超时。当我编辑HttpConnection并单击测试连接时,我收到一条错误,指出: "基础连接已关闭:无法为SSL / TLS安全通道建立信任关系。"

我尝试过使用脚本任务和同样的错误。 我甚至尝试过使用虚拟控制台应用程序并获得相同的结果。

我还有一个java编写的应用程序实际上完成了这项工作,但我无法访问它的代码隐藏。这基本上证明问题不是来自服务器本身。 java应用程序拥有自己的密钥库和我在服务器上安装的相同证书。

我打开了一个wireshark捕获,我看到当我使用我的任何一个应用程序时,主机发出了一个DNS请求,我没有在任何地方配置地址(它似乎是来自内部网的代理地址),而java app用正确的地址发出DNS请求。

我被困在这里,我不知道问题可能是什么,或者我还能做什么,以便我得到一个正确的错误。

请指教!

编辑:

这是调用WS的代码:

public static void CallWebService()
        {
            var _url = "https://<IP>/App/soap/DataService";
            string action = "getData";
            Dictionary<string, string> parameters = new Dictionary<string, string>();

            parameters.Add("param1", "0");
            parameters.Add("param2", "0");
            parameters.Add("param3", "value");

            XmlDocument soapEnvelopeXml = CreateSoapEnvelope(action, parameters);
            HttpWebRequest webRequest = CreateWebRequest(_url);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

            // begin async call to web request.
            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

            // suspend this thread until call is complete. You might want to
            // do something usefull here like update your UI.
            asyncResult.AsyncWaitHandle.WaitOne();

            // get the response from the completed web request.
            string soapResult;

            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
            }

            Console.WriteLine(soapResult);
        }

        private static HttpWebRequest CreateWebRequest(string url)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";

            string thumbprint = "CERTIFICATE THUMBPRINT";
            byte[] thumbprintArray = new byte[thumbprint.Split(new char[]{ ' ' }).Length];
            string[] stringArray = thumbprint.Split(new char[] { ' ' });
            for (int i = 0; i < thumbprintArray.Length; i++)
            {
                thumbprintArray[i] = Convert.ToByte(stringArray[i], 16);
            }

            X509Store localStore = new X509Store("My");
            localStore.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection certCol = localStore.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, true);

            foreach (X509Certificate cert in certCol)
            {
                if (cert.GetCertHashString() == thumbprint)
                {
                    webRequest.ClientCertificates.Add(cert);
                    break;
                }
            }

            webRequest.UseDefaultCredentials = false;
            webRequest.Credentials = new NetworkCredential("USER", "PASSWORD");

            return webRequest;
        }

        private static XmlDocument CreateSoapEnvelope(string action, Dictionary<string, string> parameters)
        {
            string formatedParameters = string.Empty;
            string paramFormat = "<{0}>{1}</{0}>";

            foreach (string key in parameters.Keys)
            {
                formatedParameters += string.Format(paramFormat, key, parameters[key]);
            }

            XmlDocument soapEnvelop = new XmlDocument();
            soapEnvelop.LoadXml(string.Format(@"
<soapenv:Envelope xmlns:soap=""http://custom/soap/"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
    <soapenv:Header/>
    <soapenv:Body>
        <soap:{0}>
            {1}
        </soap:{0}>
    </soapenv:Body>
</soapenv:Envelope>", action, formatedParameters));
            return soapEnvelop;
        }

        private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }

0 个答案:

没有答案