SOAP请求失败

时间:2019-02-20 14:49:14

标签: c# soap soapui

我正在尝试使用C#发出SOAP请求。使用SoapUI,我已经成功发出了所需的请求,因此我基本上将请求字符串复制到了以下C#代码的LoadXml中:

    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://w8cert.iconnectdata.com:443/FleetCreditWS/services/FleetCreditWS0200");
    webRequest.Headers.Add(@"SOAP:Action");
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";

    XmlDocument soapEnvelopeXml = new XmlDocument();

    soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8"" ?><soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:main=""http://fleetCredit02.comdata.com/maintenance/"" xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"">
        <soapenv:Header>
            <wsse:Security>
                <wsse:UsernameToken>
                    <wsse:Username>{MyUserName}</wsse:Username>
                    <wsse:Password>{MyPassword}</wsse:Password>
                    </wsse:UsernameToken>
            </wsse:Security>
            </soapenv:Header>
            <soapenv:Body>
                <main:ProprietaryIntradayRequest>
                    <startDate>2018-02-06</startDate>
                    <maskCardFlag>false</maskCardFlag>
                </main:ProprietaryIntradayRequest>
            </soapenv:Body>
        </soapenv:Envelope>");


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

    WebResponse response; 

    try
    {

        using (response = webRequest.GetResponse())
        {
            using (StreamReader rd = new StreamReader(response.GetResponseStream()))
            {
                string soapResult = rd.ReadToEnd();
                Console.WriteLine(soapResult);
            }
        }

    }
    catch (WebException e)
    {
        StreamReader str = new StreamReader(e.Response.GetResponseStream());

        System.Diagnostics.Debugger.Break();

    }

此代码在“使用(response = webRequest.GetResponse())”行上引发无聊的(500)内部服务器错误。我什至试图捕获Web异常响应,但得到同样的500错误。

谁能看到我所缺少的东西,导致相同的请求在SoapUI中工作,但在C#中失败?

0 个答案:

没有答案