Un cop està preparada tota la configuració necessària per fer la invocació només queda aquesta pròpiament dita. En l'aplicació també hi han els botons de "Load" i "Save" que el que fan és escriure els valors dels controls en un fitxer XML i recuperar els valors, no cal que els expliqui...
private string SendRequest(string SOAP,
string URL,
string SOAPAction,
string ContentType,
clsProxy pProxy,
clsHTTPBasicAuthorization HTTPBasic)
{
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(URL);
req.ContentType = ContentType;
req.Method = "POST";
if (!string.IsNullOrWhiteSpace(SOAPAction)) req.Headers.Add("SOAPAction", SOAPAction);
if (pProxy != null) req.Proxy = pProxy.GetProxy();
if (HTTPBasic != null)
{
string auth = HTTPBasic.CreateAuthorization();
req.Headers.Add("Authorization", "Basic " + auth);
}
try
{
string responseSOAP = "";
using (Stream stm = req.GetRequestStream())
{
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(SOAP);
}
}
WebResponse response = req.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
responseSOAP = reader.ReadToEnd();
return responseSOAP;
}
catch (Exception E)
{
return E.Message;
}
}
private void btnPOST_Click(object sender, EventArgs e)
{
btnPOST.Enabled = false;
try
{
string SOAPString = txtSOAP.Text;
string URL = txtURL.Text;
string SOAPAction = txtSOAPAction.Text;
clsProxy Pxy = null;
clsHTTPBasicAuthorization HTTPBasic = null;
int Iteracions = int.Parse(txtIteracions.Text);
txtResultats.Text += Environment.NewLine + DateTime.Now.ToShortDateString()
+ " " + DateTime.Now.ToLongTimeString()
+ " ----------------------" + Environment.NewLine;
if(chkUseProxy.Checked)
{
Pxy = new clsProxy();
Pxy.ProxyURL = txtProxy.Text;
Pxy.ProxyUsr = txtProxyUsr.Text;
Pxy.ProxyPwd = txtProxyPwd.Text;
Pxy.ProxyPort = txtProxyPort.Text;
}
if(chkBasicAuth.Checked)
{
HTTPBasic = new clsHTTPBasicAuthorization();
HTTPBasic.Domini = txtDominiBasicAuth.Text;
HTTPBasic.Usr = txtUsuariBasicAuth.Text;
HTTPBasic.Pwd = txtPwdBasicAuth.Text;
}
for (int i = 0; i < Iteracions; i++)
{
txtResultats.Text += Environment.NewLine + DateTime.Now.ToLongTimeString()
+ SendRequest(SOAPString, URL, SOAPAction, cboContentType.Text, Pxy, HTTPBasic);
Application.DoEvents();
}
txtResultats.Text += Environment.NewLine
+ DateTime.Now.ToLongTimeString()
+ " ----------------------" + Environment.NewLine;
}
catch (Exception E)
{
txtResultats.Text += Environment.NewLine
+ "--------- ERRRORRR -------------" + Environment.NewLine;
txtResultats.Text += Environment.NewLine + E.Message;
}
btnPOST.Enabled = true;
}
|