public string ExecutarRequisicao(string userAgent, string contentType, MetodosWebService method, string body, Dictionary <string, string> dadosAutenticacao, bool isBasic, bool isHeader) { WsConexao ws = new WsConexao(urlWebService, usuarioWebService, senhaWebService); WebHeaderCollection header = null; if (isHeader && dadosAutenticacao.Keys.Count > 0) { header = MontarHeader(dadosAutenticacao["keyUser1"], dadosAutenticacao["valuePass1"], dadosAutenticacao["keyUser2"], dadosAutenticacao["valuePass2"]); } return(ws.Executar(userAgent, contentType, method, header, body, isBasic, isHeader)); }
public string BuscarDadosWebService(string userAgent, string contentType, string body, int metodo, string headerkey, string headerValue, bool isHeader, bool isBasic) { Dictionary <string, string> dadosAutentica = null; PaginaDAO paginaDAO = new PaginaDAO(urlWebService, usuarioWebService, senhaWebService); if (isHeader) { dadosAutentica = new Dictionary <string, string>(); dadosAutentica.Add(usuarioWebService, senhaWebService); dadosAutentica.Add(headerkey, headerValue); } if (!string.IsNullOrEmpty(body)) { //TODO: montagem do body em formato json } MetodosWebService method = this.BuscarMetodoWebService(metodo); return(paginaDAO.BuscarDadosWebService(userAgent, contentType, body, method, dadosAutentica, isBasic, isHeader)); }
public string Executar(string userAgent, string contentType, MetodosWebService method, WebHeaderCollection header, string body, bool isBasic, bool isHeader) { string result = ""; try { var httpResquest = (HttpWebRequest)WebRequest.Create(urlWebService); httpResquest.Method = method.ToString(); if (!string.IsNullOrEmpty(contentType)) { httpResquest.ContentType = contentType; } if (!string.IsNullOrEmpty(userAgent)) { httpResquest.UserAgent = userAgent; } if (isBasic) { SetAutenticationBasic(httpResquest, usuarioWebService, senhaWebService); } else if (isHeader && header != null) { httpResquest.Headers = header; } else if (!string.IsNullOrEmpty(usuarioWebService) && !string.IsNullOrEmpty(senhaWebService)) { NetworkCredential credential = new NetworkCredential(); credential.UserName = usuarioWebService.Trim(); credential.Password = senhaWebService.Trim(); httpResquest.Credentials = credential; } if (proxy != null) { httpResquest.Proxy = proxy; } if (method == MetodosWebService.POST && !string.IsNullOrEmpty(body)) { var request = new StreamWriter(httpResquest.GetRequestStream()); request.Write(body); request.Flush(); request.Close(); } using (var response = httpResquest.GetResponse()) { var streamDados = response.GetResponseStream(); var reader = new StreamReader(streamDados); result = reader.ReadToEnd(); } } catch (WebException ex) { result = ex.ToString(); } return(result); }
public string BuscarDadosWebService(string userAgent, string contentType, string body, MetodosWebService method, Dictionary <string, string> dadosAutenticacao, bool isBasic, bool isHeader) { WsRequisicao ws = new WsRequisicao(urlWebService, usuarioWebService, senhaWebService); string resultado = ws.ExecutarRequisicao(userAgent, contentType, method, body, dadosAutenticacao, isBasic, isHeader); return(resultado); }