0

I have a piece of code written in C#.Net which reads from a database, collects records, builds a SOAP envelope around them and sends them to the following URL:

https://nodeD1.production.webservices.amadeus.com/SECRETNUMBER

I am able to copy my SOAP envelope string outputted from my code and paste it into SOAPUI, and it works flawlessly. But when I try to send it to the URL through my code, I always get:

The remote server returned an error: (500) Internal Server Error.

My entire SOAP xml request (including the soap header and everything else) is a single string by the time my code is done building it, and I have tried sending to the URL using the following code:

            ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertficate;

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

            string httpResponseString = "";

            webRequest.Proxy = null; //This will result in a quicker post.

            byte[] requestBytes = null;
            byte[] responseBytes = null;

            requestBytes = System.Text.Encoding.UTF8.GetBytes(xmlRequestString);

            //Set HttpWebRequest properties
            webRequest.Method = "POST";
            webRequest.ContentLength = requestBytes.Length;
            webRequest.ContentType = "application/soap+xml;charset=UTF-8;";
            //webRequest.Headers.Add("SOAPAction: http://webservices.amadeus.com/Profile_PartialUpdateNGProfile_11.1");
            //webRequest.ContentType = "text/xml";

            using (Stream requestStream = webRequest.GetRequestStream())
            {
                requestStream.Write(requestBytes, 0, requestBytes.Length);
            }

            try
            {

                using (var response = (HttpWebResponse)webRequest.GetResponse())
                {
                    Stream stream = response.GetResponseStream();

                    using (MemoryStream ms = new MemoryStream())
                    {
                        int count = 0;

                        do
                        {
                            byte[] buf = new byte[1024];
                            count = stream.Read(buf, 0, 1024);
                            ms.Write(buf, 0, count);
                        }
                        while (stream.CanRead && count > 0);

                        responseBytes = ms.ToArray();
                    }
                }



                httpResponseString = System.Text.Encoding.Default.GetString(responseBytes);

            }
            catch (Exception e)
            {
                return e.Message;
            }

            return httpResponseString;

Am I forgetting something obvious? I have been stuck on this problem for a couple days now and I'm not sure what it could be. I have tried commenting and uncommenting the line:

webRequest.Headers.Add("SOAPAction: http://webservices.amadeus.com/Profile_PartialUpdateNGProfile_11.1");

But no dice.

NOTE: My piece of code is an asp.net web service (so I am a web service trying to communicate with another web service), could it be something in my Web.config file that's causing this?

PaulG
  • 6,920
  • 12
  • 54
  • 98

1 Answers1

0

Looks like all I had to do in my case was change my soap action in my soap envelope from:

https://nodeD1.production.webservices.amadeus.com/SECRETNUMBER

to:

https://noded1.production.webservices.amadeus.com/SERCRETNUMBER

Thanks to Fiddler I was able to see the following message:

<faultstring>A header representing a Message Addressing Property is not valid and the message cannot be processed</faultstring>

I Googled the error message and I found a StackOverflow post about it:

Error in Amadeus Service: A header representing a Message Addressing Property is not valid and the message cannot be processed

Apparently .net doesn't like capital letters in URLs in SOAP envelopes. The thing is I thought this might be the case, but I tried with lowercase and it still failed because my SOAP envelope wasn't properly built.

Community
  • 1
  • 1
PaulG
  • 6,920
  • 12
  • 54
  • 98