// This event handler deals with the results of the background operation. private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { startButton.Enabled = true; stopButton.Enabled = false; SoapResponse response = e.Result as SoapResponse; if (e.Cancelled == true) { soapTesterStatus.Text = "Canceled!"; } else if (e.Error != null) { soapTesterStatus.Text = "Error: " + e.Error.Message; } else { soapTesterStatus.Text = "Done!"; } if (response.IsError) { responseTextBox.BackColor = Color.LightPink; responseTextBox.Text = "Response:" + response.Response + Environment.NewLine + Environment.NewLine + "Error:" + response.Error; } else { responseTextBox.BackColor = Color.PaleGreen; responseTextBox.Text = response.Response; } }
private SoapResponse Execute() { SoapResponse soapResponse = new SoapResponse(); try { HttpWebRequest request = this.CreateWebRequest(this.Request.Url); XmlDocument soapEnvelopeXml = new XmlDocument(); soapEnvelopeXml.LoadXml(this.Request.SoapXml); using (Stream stream = request.GetRequestStream()) { soapEnvelopeXml.Save(stream); } using (WebResponse response = request.GetResponse()) { using (StreamReader rd = new StreamReader(response.GetResponseStream())) { string soapResult = rd.ReadToEnd(); soapResponse.Response = soapResult; } } } catch (SoapException soapEx) { soapResponse.Response += soapEx.Detail.ToString(); soapResponse.Error = soapEx.ToString(); } catch (Exception ex) { soapResponse.Error = ex.ToString(); } return(soapResponse); }