Внутренняя ошибка сервера (500) при выполнении запроса SOAP - PullRequest
1 голос
/ 15 марта 2012

Я пытаюсь выполнить запрос SOAP, но сервер возвращает ошибку 500.Например, SOAP-запрос корректно возвращает XML-сообщение через jmeter, поэтому в моем коде должно быть что-то, но я не вижу, что именно.Вы можете помочь?

private void soapRequest(string regID)
        {

            string soapReq= @"<?xml version=""1.0"" encoding=""utf-8""?>";
            soapReq= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mpc=\"urn://mobility-platform.de/mpcustomerdb/\">\n";
            soapReq += "<soapenv:Header/>\n";
            soapReq += "<soapenv:Body>\n";
            soapReq += "<mpc:findRegistrationByID>\n";
            soapReq += "<registrationID>" + regID + "</registrationID>\n";
            soapReq += "</mpc:findRegistrationByID>\n";
            soapReq += "</soapenv:Body>\n";
            soapReq += "</soapenv:Envelope>";

            //Builds the connection to the WebService.
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://url?wsdl");
            req.Credentials = new NetworkCredential("user", "pass");            
            req.Headers.Add("SOAP:Action");
            req.ContentType = "text/xml;charset=\"utf-8\"";
            req.Accept = "text/xml";
            req.Method = "POST";

            //Passes the SoapRequest String to the WebService
            using (Stream stm = req.GetRequestStream())
            {
                using (StreamWriter stmw = new StreamWriter(stm))
                {
                    stmw.Write(soapReq.ToString());                    
                }
            }
            try
            {
                //Gets the response
                HttpWebResponse soapResponse = (HttpWebResponse)req.GetResponse();
                //Writes the Response
                Stream responseStream = soapResponse.GetResponseStream();
                //read the stream
                XmlDocument soapResponseXML = new XmlDocument();

                StreamReader responseStreamRead = new StreamReader(responseStream);
                soapResponse.ContentType = "text/xml";
                //MessageBox.Show(responseStreamRead.ReadToEnd().ToString());
                string soapURL = responseStreamRead.ReadToEnd().ToString();

                soapResponseXML.LoadXml(soapURL);
            }
            catch (Exception ex)
            {                
                MessageBox.Show("Error: " + ex.Message);
            }
        }

Вот запрос на мыло

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mpc="urn://mobility-platform.de/mpcustomerdb/">
   <soapenv:Header/>
   <soapenv:Body>
      <mpc:findRegistrationByID>
         <registrationID>2304580</registrationID>
      </mpc:findRegistrationByID>
   </soapenv:Body>
</soapenv:Envelope>

Позже отредактируйте: Если я изменю
req.Headers.Add("SOAP:Action"); на:
req.Headers.Add("SOAPAction", ""\"http://url\"" + "findRegistrationByID"); Я получаю другую ошибку: "Это свойство не реализовано этим классом"

1 Ответ

0 голосов
/ 11 апреля 2012

Нелегко сделать правильный запрос на мыло с помощью этого метода. Я настоятельно рекомендую использовать весь веб-сервис, а сделать запрос следующим образом:

WebService aa = new WebService;
registrationName = aa.findRegistrationByID("123");

Это выполнит весь код выше;)

...