mercredi 9 septembre 2020

Soap message connection

I have problem with Soap request.

This is my code.

 public void InvokeService()
        {
            try
            {
                //Calling CreateSOAPWebRequest method  
                System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return true; };
                string action = @"pobierzOswiadczenie ";
                XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
                HttpWebRequest webRequest = CreateSOAPWebRequest(action);
                InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);       
                        
                //Geting response from request  
                using (WebResponse webResponse = webRequest.GetResponse())
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        //reading stream  
                        var ServiceResult = rd.ReadToEnd();
                        //writting stream result on console  
                        Console.WriteLine(ServiceResult);
                        Console.ReadLine();
                    }
                }
            }
            catch (WebException webex)
            {
                WebResponse errResp = webex.Response;
                using (Stream respStream = errResp.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(respStream);
                    string text = reader.ReadToEnd();
                }
            }
        }

public HttpWebRequest CreateSOAPWebRequest(string action)
        {
            //Making Web Request  
            string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("ezla_ag:ezla_ag"));
            HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(@"https://193.105.143.152:8001/ws/zus.channel.gabinetoweV2:zla");
            //SOAPAction  
            Req.Headers.Add("SOAPAction", action);
            //Content_type  
            Req.ContentType = "application/soap+xml;charset=\"utf-8\"";
            Req.Accept = "text/xml";
            Req.Headers["Authorization"] = "Basic " + encoded;
            //HTTP method  
            Req.Method = "POST";
            //return HttpWebRequest  
            return Req;
        }

        private static XmlDocument CreateSoapEnvelope()
        {
            XmlDocument SOAPReqBody = new XmlDocument();
            SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>  
                <soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" xmlns:zus=""https://193.105.143.152:8001/ws/zus.channel.gabinetoweV2:zla"">
                   <soap:Header/>
                   <soap:Body>
                    <zus:pobierzOswiadczenie/>
                   </soap:Body>
                  </soap:Envelope>");

            return SOAPReqBody;
        }

        private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }   

I need to get data from soap request, but all the time I get error that "The system is not able to identify the service endpoint for service EPR '172.16.25.152/ws/zus.channel.gabinetoweV2:zla'".

I got stuck. Do you have any idea where problem can be?




Aucun commentaire:

Enregistrer un commentaire