private void btnGetSOAP_Click(object sender, EventArgs e) { try { string xmlData = editor.GetAllText(); notepad.FileNew(); editor.SetXML(WDWebService.WrapSOAP("username", "password", xmlData) + Environment.NewLine); } catch (Exception ex) { MessageBox.Show(ex.Message, "SOAP Generator Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static string CallAPI(string username, string password, string url, string xmlData) { try { using (var webClient = new WebClient()) { webClient.Headers.Add("Content-Type", "text/xml; charset=utf-8"); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; webClient.Credentials = new NetworkCredential(username, password); byte[] data = Encoding.UTF8.GetBytes(WDWebService.WrapSOAP(username, password, xmlData)); byte[] rData = webClient.UploadData(url, data); return(new XDeclaration("1.0", "UTF-8", null).ToString() + Environment.NewLine + XDocument.Parse(Encoding.UTF8.GetString(rData)).ToString() + Environment.NewLine); } } catch (WebException webEx) { String responseFromServer = webEx.Message.ToString() + Environment.NewLine; if (webEx.Response != null) { using (WebResponse response = webEx.Response) { Stream dataRs = response.GetResponseStream(); using (StreamReader reader = new StreamReader(dataRs)) { try { responseFromServer += XDocument.Parse(reader.ReadToEnd()); } catch { // ignore exception } } } } return(responseFromServer); } }