HttpWebRequest 500内部错误,但是SOAPUI可以工作

时间:2018-11-28 04:14:31

标签: soap httpwebrequest

我收到错误消息“远程服务器返回错误:(500)内部服务器错误。”状态代码为“ ProtocolError”

HttpWebRequest webRequest = null;

XmlDocument soapEnvelopeXml = new XmlDocument();
string requestEnvelopeString = SerializerHelper.ToRequestEnvelopeString(request);

soapEnvelopeXml.LoadXml(requestEnvelopeString);

webRequest = (HttpWebRequest)WebRequest.Create(<<endpointUrl>>);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
webRequest.KeepAlive = true;
webRequest.ProtocolVersion = HttpVersion.Version11;

using (Stream stream = webRequest.GetRequestStream())
{
   soapEnvelopeXml.Save(stream);
}

try
{
   using (WebResponse webResponse = webRequest.GetResponse())
   {
      using (StreamReader reader = new StreamReader(webResponse.GetResponseStream()))
      {
         string responseEnvelopeString = reader.ReadToEnd();
      }
   }
}
catch (WebException ex)
{
   string exMessage = ex.Message;
}

当我直接通过SOAPUI发送requestEnvelopeString时,它可以工作,有人可以建议如何解决此问题吗?

1 个答案:

答案 0 :(得分:0)

发现问题是缺少SOAP-ACTION标头,SOAPUI将自动添加到请求中。

谢谢 薄荷糖