/// <summary> /// Metodo que Realiza a consulta /// O retorno é do tipo ResultadoConsulta /// </summary> /// <param name="filtro">Parametros para a consulta</param> /// <returns></returns> public ResultadoConsulta Consultar(FiltroConsulta filtro) { String URI = _Dominio + "/api/Consulta"; String encoded = _UserEncoded; String requestXml = XMLHelpers.SerializeObjectToXML <FiltroConsulta>(filtro); byte[] bytes; bytes = System.Text.Encoding.ASCII.GetBytes(requestXml); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URI); request.Method = "POST"; request.Headers.Add("Authorization", "Basic " + encoded); request.ContentType = "application/xml"; request.ContentLength = bytes.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); } try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream dataStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(dataStream)) { String result = String.Empty; result = reader.ReadToEnd(); return(XMLHelpers.DeserializeXMLToObject <ResultadoConsulta>(result)); } } } } catch (WebException Webex) { using (Stream dataStream = Webex.Response.GetResponseStream()) { using (StreamReader reader = new StreamReader(dataStream)) { String result = String.Empty; result = reader.ReadToEnd(); throw new Exception(result, Webex); } } } catch (Exception ex) { throw ex; } }