Exemplo de implementação dos serviços
Serviço (C#)
using System; using System.Net; using System.Net.Http; namespace IWS_Exemplo.Servicos { public class Servico { public static async void Get(string token, string cnpj, string codigo, string uf, string descricao = "", string unidadeMedida = "", decimal valor = 0) { using (var client = new HttpClient()) { var url = string.Format("http://iws.ibpt.org.br/api/deolhonoimposto/Servicos?token={0}&cnpj={1}&codigo={2}&uf={3}&descricao={4}&unidadeMedida={5}&valor={6}", token, cnpj, codigo, uf, descricao, unidadeMedida, valor); var response = await client.GetAsync(url); if (response.StatusCode == HttpStatusCode.OK) { var servico = await response.Content.ReadAsAsync<ServicoDTO>(); Console.WriteLine("Serviço: {0} - {1}", produto.Codigo, produto.Descricao); } else { Console.WriteLine("Falha"); } } } } }
NFE (C#)
using System; using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; namespace IWS_Exemplo.Servicos { public class NFE { public static async void Post(string token, string localFilePath) { using (var httpClient = new HttpClient()) { using (var formData = new MultipartFormDataContent()) { var fileContent = new ByteArrayContent(File.ReadAllBytes(localFilePath)); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "nfe" }; formData.Add(fileContent); var response = await httpClient.PostAsync(string.Concat("http://iws.ibpt.org.br/api/deolhonoimposto/NFE?token=", token), formData); if (response.StatusCode == HttpStatusCode.OK) { var nfe = await response.Content.ReadAsAsync<NFEDTO>(); Console.WriteLine("{0} - Quantidade de itens: {1}", nfe.Chave, nfe.Produtos.Count); } else { Console.WriteLine("Falha"); } } } } } }
Produtos (C#)
using System; using System.Net; using System.Net.Http; namespace IWS_Exemplo.Servicos { public class Produto { public static async void Get(string token, string cnpj, string codigo, string uf, int ex, string codigoInterno = "", string descricao = "", string unidadeMedida = "", decimal valor = 0, string gtin = "") { using (var client = new HttpClient()) { var url = string.Format("http://iws.ibpt.org.br/api/deolhonoimposto/Produtos?token={0}&cnpj={1}&codigo={2}&uf={3}&ex={4}&codigoInterno={5}&descricao={6}&unidadeMedida={7}&valor={8}>in={9}", token, cnpj, codigo, uf, ex, codigoInterno, descricao, unidadeMedida, valor, gtin); var response = await client.GetAsync(url); if (response.StatusCode == HttpStatusCode.OK) { var produto = await response.Content.ReadAsAsync<ProdutoDTO>(); Console.WriteLine("Produto: {0} - {1}", produto.Codigo, produto.Descricao); } else { Console.WriteLine("Falha"); } } } } }