远程服务器返回错误:(500)内部服务器错误。 - SSIS Web服务呼叫

时间:2018-05-04 07:40:12

标签: c# web-services ssis

--------- SSIS脚本任务失败---------

我在SSIS脚本任务中使用此方法调用Web服务但作为响应,我得到The remote server returned an error: (500) Internal Server Error

堆栈跟踪中没有其他内容。当我在Soap UI中使用相同的XML请求时,我得到了有效的响应。在Soap UI中,我使用基本身份验证。

任何人都可以帮助我。这可能是什么问题?

public void GetWebServiceData(DataRow row)
    {

        FileInfo MyFileinfo = new FileInfo(configuration_file_location + "\\Test1\\Test.xml");
        using (StreamReader myReader = MyFileinfo.OpenText())
        {
            myXmlMessage = myReader.ReadToEnd();
        }

        try
        {
            myXmlMessage = AddContractToXml(policyNumber, myXmlMessage);
            int timeout = 1800000;

            HttpWebRequest req = WebRequest.Create(new Uri(web_service_url))
                   as HttpWebRequest;
            req.Method = "POST";
            req.ContentType = "text/xml;charset=UTF-8";
            byte[] formData = UTF8Encoding.UTF8.GetBytes(myXmlMessage.ToString());

            req.ContentLength = formData.Length;
            req.Timeout = timeout;

            ICredentials credentials = new NetworkCredential(user_name, user_password);
            WebProxy myProxy = new WebProxy(proxy_server, proxy_port);

            req.Proxy = myProxy;
            req.Proxy.Credentials = CredentialCache.DefaultCredentials;
            req.Credentials = credentials;

            using (Stream post = req.GetRequestStream())
            {
                post.Write(formData, 0, formData.Length);
            }

            using (HttpWebResponse resp = req.GetResponse()
                                          as HttpWebResponse)
            {
                using (StreamReader reader =
                    new StreamReader(resp.GetResponseStream()))
                {
                    XmlDocument myXmlDoc = new XmlDocument();
                    myXmlDoc.Load(reader);
                    XslCompiledTransform myXslTrans = new XslCompiledTransform();
                    /* loading XSLT */
                    myXslTrans.Load(configuration_file_location + "\\Test1\\TestMonitoring.xslt");
                    /* creating Output Stream */
                    XmlTextWriter myWriter = new XmlTextWriter(web_service_output_transform_location + policyNumber + ".xml", null);
                    /* XML transformation */
                    myXslTrans.Transform(myXmlDoc, null, myWriter);
                    myWriter.Close();

                }
            }

        }
        catch (WebException webExcp)
        {
            string exMessage = webExcp.Message;

            if (webExcp.Response != null)
            {
                using (StreamReader responseReader = new StreamReader(webExcp.Response.GetResponseStream()))
                {
                    exMessage = responseReader.ReadToEnd();
                    if (!Directory.Exists(log_location + DateTime.Now.ToString("ddMMyyyy")))
                        Directory.CreateDirectory(log_location + DateTime.Now.ToString("ddMMyyyy"));
                    FileStream file = new FileStream(log_location + "//" + DateTime.Now.ToString("ddMMyyyy") + "//" + policyNumber + ".xml", FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter writer = new StreamWriter(file);
                    writer.Write(exMessage);
                    writer.Close();
                    file.Close();
                }
            }
            Dts.TaskResult = (int)ScriptResults.Failure;
            return;
        }
        catch (Exception e)
        {
            Dts.TaskResult = (int)ScriptResults.Failure;
            return;
        }
        finally
        {

        }
    }

0 个答案:

没有答案