将xml发送到SOAP Web服务,返回错误500

时间:2015-01-12 14:39:07

标签: c# .net web-services

我有一段用C#.Net编写的代码,它从数据库中读取,收集记录,围绕它们构建SOAP信封并将它们发送到以下URL:

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

我能够复制从我的代码输出的SOAP信封字符串并将其粘贴到SOAPUI中,并且它可以完美地工作。但是当我尝试通过我的代码将其发送到URL时,我总是得到:

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

我的代码构建完成后,我的整个SOAP xml请求(包括soap标头和其他所有内容)都是单string,我尝试使用以下代码发送到URL:

            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;

我忘了一些明显的东西吗?我已经坚持这个问题几天了,我不知道它可能是什么。我试过评论并取消注释该行:

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

但没有骰子。

注意:我的代码是一个asp.net Web服务(所以我是一个尝试与另一个Web服务通信的Web服务),它可能是我的Web.config文件中导致的此?

1 个答案:

答案 0 :(得分:0)

在我的案例中,我所要做的就是在我的肥皂信封中改变我的肥皂行为:

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

为:

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

感谢Fiddler,我能够看到以下消息:

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

我用Google搜索了错误消息,我找到了一篇关于它的StackOverflow帖子:

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

显然.net不喜欢SOAP信封中URL中的大写字母。事情是我认为可能是这种情况,但我尝试使用小写但它仍然失败,因为我的SOAP信封没有正确构建。