Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this method in SSIS Script task which calls a web services but in response, I am getting The remote server returned an error: (500) Internal Server Error.

There is nothing else in the stack trace. When I use the same XML request in a Soap UI I get a valid response. In Soap UI I use Basic Authentication.

Can anyone help me out here. What could be the issue here?

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
        {

        }
    }


What I have tried:

Tried in Soap UI and its working.
Posted
Comments
F-ES Sitecore 4-May-18 4:10am    
You'll need to use a tool like Fiddler, or some other network scanner to look at the http call. There is probably a more detailed error message in the response that can help you, you can also compare the working call with the non-working call to see how they differ.
GKP1992 4-May-18 4:21am    
Try using the XML generated by your code to call the service from SOAP UI. Maybe your code does not create the XML you want.
Member 13789919 4-May-18 4:22am    
I have checked that, its producing the correct one. Checked the same XML in soap and its working fine.
Afzaal Ahmad Zeeshan 4-May-18 11:38am    
The problem is on the server-side, do you have access to the server-side code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900