Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/11/2016, 12:54
Avatar de CCB
CCB
 
Fecha de Ingreso: noviembre-2009
Ubicación: Perú
Mensajes: 65
Antigüedad: 14 años, 6 meses
Puntos: 3
Soap en C#, traducido desde PHP

Buenas tardes,
Extrañaba escribir en el foro, pero tengo un problema que quizá puedan ayudarme. Resulta que tengo una aplicación en PHP para hacer consultas a una API, pero estoy intentando traducirlo al lenguaje C#, pero sin éxito.

Código PHP:
$datos= new SoapClient($url$conf);
        
$parametros=array(); 
$parametros['StringXML']= $StringXML;

// En PHP, tan solo envio los parametros a $datos y me funciona
$result $datos->CrearTicket($parametros);

//Luego consulto la respuesta y puedo trabajar.
echo 'Respuesta en formato xml: ' $result->CrearTicketResult '<br>'
Pero en C#, intento con HttpClient, y no logro hacerlo funcionar.

Código C#:
Ver original
  1. // Archivo ConsultaController
  2.  
  3. [HttpPost]
  4.         public ActionResult Consulta()
  5.         {
  6.             Global global = new Global();
  7.  
  8.             global.RunAsync().Wait();
  9.  
  10.             return Content("Ok");
  11.         }
  12.  
  13.  
  14. // Archivo Global.cs
  15. static async Task<Uri> EnviarDatosXML(string xml)
  16.         {
  17.             HttpResponseMessage response = await client.PostAsXmlAsync("CrearTicket", xml);
  18.             response.EnsureSuccessStatusCode();
  19.  
  20.             // return URI of the created resource.
  21.             return response.Headers.Location;
  22.         }
  23.  
  24.         static async Task<XmlDocument> ObtenerRespuestXML(string path)
  25.         {
  26.             XmlDocument product = null;
  27.             HttpResponseMessage response = await client.GetAsync(path);
  28.             if (response.IsSuccessStatusCode)
  29.             {
  30.                 product = await response.Content.ReadAsAsync<XmlDocument>();
  31.             }
  32.             return product;
  33.         }
  34.  
  35.  
  36.         public async Task RunAsync()
  37.         {
  38.             client.BaseAddress = new Uri(URL_API);
  39.             client.DefaultRequestHeaders.Accept.Clear();
  40.             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  41.  
  42.             try
  43.             {
  44.                 string xmlDoc = GeneralStringXML("99999", "1000.00", "DANI", "O", "LIMA", "AV LIMA", "[email protected]", "");
  45.                 XmlDocument ResXmlDoc = null;
  46.                 var url = await EnviarDatos(xmlDoc);
  47.  
  48.                 Debug.WriteLine(url);
  49.  
  50.  
  51.                 // Get the product
  52.                 ResXmlDoc  = await ObtenerRespuestXML(url.PathAndQuery);
  53.  
  54.  
  55.                 //XmlNodeList xrw = ResXmlDoc.GetElementsByTagName("DNI");
  56.                 //XmlNodeList xLista = ((XmlElement)xrw [0]).GetElementsByTagName("CARGO");
  57.  
  58.                 foreach (XmlElement nodo in xLista)
  59.                 {
  60.                     string xEdad = nodo.GetAttribute("EDAD");
  61.                     string xNombre = nodo.InnerText;
  62.                 }
  63.             }
  64.             catch (Exception e)
  65.             {
  66.                 Console.WriteLine(e.Message);
  67.             }
  68.         }