Al implementar un cliente de un
Servicio Web se presentaba un error al momento de intentar hacer el
consumo desde VisualStudio, pero desde SoapUI respondía perfectamente.
Para esto me valí de SoapUI para copiar el Request que este genera y el valor del Header SOAPAction (myReq.Headers.Add("SOAPAction", "")).
La función para este caso fue:
<pre
class
=
"brush:csharp"
>
private System.Data.DataSet xmlResponse(string NumeroReferencia) { System.Data.DataSet ds = new System.Data.DataSet(); try { string xml; xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:bce=\"http://j2ee.netbeans.org/wsdl/BpelBceSGI/BceInformacionOperacion\">" + "<soapenv:Header/>" + " <soapenv:Body>" + " <bce:BceInformacionOperacionOperation>" + " <numReferenciaSgiMef>" + NumeroReferencia + "</numReferenciaSgiMef>" + " </bce:BceInformacionOperacionOperation>" + " </soapenv:Body>" + "</soapenv:Envelope>"; string urlconfig = "https://192.168.254.3/BceInformacionOperacionService/BceInformacionOperacionPort"; string url = urlconfig; ////string responsestring = ""; System.Net.HttpWebRequest myReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] buffer = encoding.GetBytes(xml); string response; myReq.AllowWriteStreamBuffering = false; myReq.Method = "POST"; myReq.ContentType = "text/xml; charset=UTF-8"; myReq.ContentLength = buffer.Length; myReq.Headers.Add("SOAPAction", ""); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender1, certificate, chain, sslPolicyErrors) => true); using (Stream post = myReq.GetRequestStream()) { post.Write(buffer, 0, buffer.Length); } System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myReq.GetResponse(); Stream responsedata = myResponse.GetResponseStream(); StreamReader responsereader = new StreamReader(responsedata); response = responsereader.ReadToEnd(); ds.ReadXml(new XmlTextReader(new StringReader(response))); myResponse.Close(); responsereader.Close(); responsedata.Close(); return ds; } catch (Exception ex) { return null; } finally { ds.Dispose(); } }
</
pre
>
No hay comentarios. :
Publicar un comentario