Call AXIS service with C#

Asked

Viewed 143 times

1

I need to consume this service in a C application#:

https://tidigital.voegol.com.br/arsys/WSDL/public/ars-tidigital/GOL_Requisicao

But I can’t add it as a reference in the project. In trying to do so, I receive the following message:

Hi there, this is an AXIS service! Perhaps there will be a form for invoking the service here...

That’s why I’m trying to request via Httpwebrequest.

public class SoapProxy
    {
        private const string userName = "xxxx";
        private const string password = "xxxx";

        public static string ServicoRequisicao(string chamado)
        {
            var _url = "https://tidigital.voegol.com.br/arsys/WSDL/public/ars-tidigital/GOL_Requisicao";
            var _action = "http://tidigital.voegol.com.br/arsys/services/ARService?server=ars-tidigital&webService=GOL_Requisicao"; //https://tidigital.voegol.com.br/arsys/WSDL/public/ars-tidigital/GOL_Requisicao/Lista

            XmlDocument soapEnvelopeXml = RequisicaoSoap(chamado);
            HttpWebRequest webRequest = CreateWebRequest(_url, _action);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
            asyncResult.AsyncWaitHandle.WaitOne();

            string soapResult;
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
            }
            return soapResult;
        }


        private static HttpWebRequest CreateWebRequest(string url, string action)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Headers.Add("SOAPAction", action);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }

        private static XmlDocument RequisicaoSoap(string chamado)
        {
            XmlDocument soapEnvelop = new XmlDocument();
            //            soapEnvelop.LoadXml(string.Format(@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:GOL_Requisicao"">
            //   <soapenv:Body>
            //      <urn:Lista>
            //         <urn:Chamado>{0}</urn:Chamado>
            //      </urn:Lista>
            //   </soapenv:Body>
            //</soapenv:Envelope>", chamado));

            soapEnvelop.LoadXml(string.Format(@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:GOL_Requisicao"">
               <soapenv:Header>
                  <urn:AuthenticationInfo>
                     <urn:userName>{0}</urn:userName>
                     <urn:password>{1}</urn:password>
                  </urn:AuthenticationInfo>
               </soapenv:Header>
               <soapenv:Body>
                  <urn:Lista>
                     <urn:Chamado>{2}</urn:Chamado>
                  </urn:Lista>
               </soapenv:Body>
            </soapenv:Envelope>", userName, password, chamado));
            return soapEnvelop;
        }

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

Analyzing the service by SOAPUI, it has this structure.

inserir a descrição da imagem aqui

When I try to perform the so-called service, I’m not getting to the method "List".

The service is simply giving me back the entire WSDL structure.

This service also does not function as "Service Reference" as described by Thiago Loureiro

golReq.GOL_RequisicaoService req = new golReq.GOL_RequisicaoService();
            golReq.StatusType status = new golReq.StatusType();
            golReq.OutputMapping6Workinfo[] wi = null;
            string reqId = "";

            var x = req.Lista("REQ000000131412", out reqId, out status, out wi);
            return x;

When executing this code I get this error:

System.Net.Webexception: Request failed with empty response.

1 answer

0

Otavio, First in your project go to References, Add Service Reference Click on Advanced

inserir a descrição da imagem aqui

click on Add Web Reference inserir a descrição da imagem aqui

Enter the url and choose a friendly name for your reference:

inserir a descrição da imagem aqui

I made it to the list:

inserir a descrição da imagem aqui

  • Thanks Thiago, I had already tried this way. But it didn’t work. I get another error running this way.

  • What mistake you get this way?

  • System.Net.Webexception: Request failed with empty response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.