Ah bom!
Eu tenho esse código em C#
:
public string SendRequest(string data, string action)
{
try
{
WebRequestHandler handler = new WebRequestHandler();
if (this.Certificado != null)
handler.ClientCertificates.Add(this.Certificado);
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.ExpectContinue = false;
client.DefaultRequestHeaders.Add("Accept", "*/*");
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/soap+xml"));
//client.DefaultRequestHeaders.Add("SOAPAction", action);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.8806)");
client.DefaultRequestHeaders.TransferEncodingChunked = null;
StringContent queryString = new StringContent(data, Encoding.UTF8, "text/xml");
HttpResponseMessage response = client.PostAsync(new Uri(this.Url), queryString).Result;
String responseValue = string.Empty;
Stream responseStream = null;
/*
if (response != null)
{
//response.EnsureSuccessStatusCode();
this.cLastCode = response.StatusCode;
Task task = response.Content.ReadAsStringAsync().ContinueWith(t =>
{
responseValue = t.Result;
});
task.Wait();
};
*/
if (response != null)
{
Task task = response.Content.ReadAsStreamAsync().ContinueWith(t =>
{
responseStream = t.Result;
});
task.Wait();
string encoding = String.Join(",", response.Content.Headers.ContentEncoding);
if (response.Content.Headers.ContentEncoding.Contains("gzip"))
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
else if (response.Content.Headers.ContentEncoding.Contains("deflate"))
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
using (StreamReader streamReader = new StreamReader(responseStream))
{
responseValue = streamReader.ReadToEnd();
}
}
return responseValue;
}
catch (Exception ex)
{
throw ex;
}
}
public string ConsultarLoteRps(string CNPJ, string IM, string Protocolo)
{
String NfseDados = String.Format(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<ConsultarLoteRpsEnvio xmlns=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_lote_rps_envio.xsd\" " +
" xmlns:tc=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/tipos_complexos.xsd\">" +
"<Prestador>" +
"<tc:CpfCnpj>" +
"<tc:Cnpj>{0}</tc:Cnpj>" +
"</tc:CpfCnpj>" +
"<tc:InscricaoMunicipal>{1}</tc:InscricaoMunicipal>" +
"</Prestador>" +
"<Protocolo>{2}</Protocolo>" +
"</ConsultarLoteRpsEnvio>", CNPJ, IM, Protocolo);
String s = String.Format(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<S:Body>" +
"<ConsultarLoteRps xmlns=\"http://www.issnetonline.com.br/webservice/nfd\">" +
"<xml>{0}</xml>" +
"</ConsultarLoteRps>" +
"</S:Body></S:Envelope>",
NfseDados);
File.WriteAllText(cFileName.Replace(".xml", ".soap.xml"), s);
return this.SendRequest(s, "http://www.issnetonline.com.br/webservice/nfd/ConsultarLoteRps");
}
public String ConsultarNfsePorRps(String CNPJ, String IM, String RPS, String SERIE)
{
String NfseDados = String.Format(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<ConsultarNfseRpsEnvio xmlns=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_consultar_nfse_rps_envio.xsd\" " +
" xmlns:tc=\"http://www.issnetonline.com.br/webserviceabrasf/vsd/tipos_complexos.xsd\">" +
"<IdentificacaoRps>" +
"<tc:Numero>{0}</tc:Numero>" +
"<tc:Serie>{1}</tc:Serie>" +
"<tc:Tipo>1</tc:Tipo>" +
"</IdentificacaoRps>" +
"<Prestador>" +
"<tc:CpfCnpj><tc:Cnpj>{2}</tc:Cnpj></tc:CpfCnpj>" +
"<tc:InscricaoMunicipal>{3}</tc:InscricaoMunicipal>" +
"</Prestador>" +
"</ConsultarNfseRpsEnvio>", RPS, SERIE, CNPJ, IM);
String s = String.Format(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<soap:Body>" +
"<ConsultarNFSePorRPS xmlns =\"http://www.issnetonline.com.br/webservice/nfd\">" +
"<xml>{0}</xml>" +
"</ConsultarNFSePorRPS>" +
"</soap:Body>" +
"</soap:Envelope>",
NfseDados);
File.WriteAllText(cFileName.Replace(".xml", ".soap.xml"), s);
return this.SendRequest(s, "http://www.issnetonline.com.br/webservice/nfd/ConsultarNFSePorRPS");
}