Well, I finally got this to work, so I'll write here the code I'm using. (Remember, .Net 2.0, and no wsdl to get from web service).
First, we create an HttpWebRequest:
public static HttpWebRequest CreateWebRequest(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAP:Action");
webRequest.ContentType = "text/xml;charset="utf-8"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
Next, we make a call to the webservice, passing along all values needed. As I'm reading the soap envelope from a xml document, I'll handle the data as a StringDictionary. Should be a better way to do this, but I'll think about this later:
public static XmlDocument ServiceCall(string url, int service, StringDictionary data)
{
HttpWebRequest request = CreateWebRequest(url);
XmlDocument soapEnvelopeXml = GetSoapXml(service, data);
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
IAsyncResult asyncResult = request.BeginGetResponse(null, null);
asyncResult.AsyncWaitHandle.WaitOne();
string soapResult;
using (WebResponse webResponse = request.EndGetResponse(asyncResult))
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
File.WriteAllText(HttpContext.Current.Server.MapPath("/servicios/" + DateTime.Now.Ticks.ToString() + "assor_r" + service.ToString() + ".xml"), soapResult);
XmlDocument resp = new XmlDocument();
resp.LoadXml(soapResult);
return resp;
}
So, that's all. If anybody thinks that GetSoapXml must be added to the answer, I'll write it down.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…