0

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

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

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

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

我打开了一个wireshark捕获,我看到当我使用我的任何一个应用程序时,主机向一个我没有在任何地方配置的地址发出了DNS请求(它看起来像是来自Intranet的代理地址),而Java应用程序则产生了一个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);
            }
        }
4

0 回答 0