I need to consume this service in a C # application:
But I can not add as a reference in the project. When I try to do this, I get the following message:
Hi there, this is an AXIS service! Perhaps there will be a way to invoking the service here ...
So I'm trying to make the 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 through SOAPUI, it has this structure.
WhenItrytocalltheservice,Icannotreachthe"List" method.
The service is simply returning me the entire WSDL structure.
This service also does not work as a "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 I run this code I get this error:
System.Net.WebException: Request failed with empty response.