Add FrmTestSoapService

This commit is contained in:
2017-12-21 10:25:41 +01:00
parent 167abb7c75
commit 16c43862b8
5 changed files with 406 additions and 26 deletions

View File

@@ -0,0 +1,187 @@
namespace VAR.Toolbox.UI
{
partial class FrmTestSoapService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtUrl = new System.Windows.Forms.TextBox();
this.txtInterface = new System.Windows.Forms.TextBox();
this.txtMethod = new System.Windows.Forms.TextBox();
this.txtParameters = new System.Windows.Forms.TextBox();
this.txtResult = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.btnTest = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 13);
this.label1.TabIndex = 0;
this.label1.Text = "URL";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(49, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Interface";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 70);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(43, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Method";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 97);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(60, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Parameters";
//
// txtUrl
//
this.txtUrl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtUrl.Location = new System.Drawing.Point(98, 13);
this.txtUrl.Name = "txtUrl";
this.txtUrl.Size = new System.Drawing.Size(389, 20);
this.txtUrl.TabIndex = 4;
//
// txtInterface
//
this.txtInterface.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtInterface.Location = new System.Drawing.Point(98, 40);
this.txtInterface.Name = "txtInterface";
this.txtInterface.Size = new System.Drawing.Size(389, 20);
this.txtInterface.TabIndex = 5;
//
// txtMethod
//
this.txtMethod.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtMethod.Location = new System.Drawing.Point(98, 67);
this.txtMethod.Name = "txtMethod";
this.txtMethod.Size = new System.Drawing.Size(389, 20);
this.txtMethod.TabIndex = 6;
//
// txtParameters
//
this.txtParameters.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtParameters.Location = new System.Drawing.Point(98, 94);
this.txtParameters.Multiline = true;
this.txtParameters.Name = "txtParameters";
this.txtParameters.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtParameters.Size = new System.Drawing.Size(389, 103);
this.txtParameters.TabIndex = 7;
//
// txtResult
//
this.txtResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtResult.Location = new System.Drawing.Point(12, 234);
this.txtResult.Multiline = true;
this.txtResult.Name = "txtResult";
this.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtResult.Size = new System.Drawing.Size(475, 196);
this.txtResult.TabIndex = 8;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 215);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(37, 13);
this.label5.TabIndex = 9;
this.label5.Text = "Result";
//
// btnTest
//
this.btnTest.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnTest.Location = new System.Drawing.Point(412, 203);
this.btnTest.Name = "btnTest";
this.btnTest.Size = new System.Drawing.Size(75, 23);
this.btnTest.TabIndex = 10;
this.btnTest.Text = "Test";
this.btnTest.UseVisualStyleBackColor = true;
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
//
// FrmTestSoapService
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(499, 442);
this.Controls.Add(this.btnTest);
this.Controls.Add(this.label5);
this.Controls.Add(this.txtResult);
this.Controls.Add(this.txtParameters);
this.Controls.Add(this.txtMethod);
this.Controls.Add(this.txtInterface);
this.Controls.Add(this.txtUrl);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FrmTestSoapService";
this.Text = "TestSoapService";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtUrl;
private System.Windows.Forms.TextBox txtInterface;
private System.Windows.Forms.TextBox txtMethod;
private System.Windows.Forms.TextBox txtParameters;
private System.Windows.Forms.TextBox txtResult;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btnTest;
}
}

View File

@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace VAR.Toolbox.UI
{
public partial class FrmTestSoapService : Form
{
public FrmTestSoapService()
{
InitializeComponent();
}
private void btnTest_Click(object sender, EventArgs e)
{
try
{
string url = txtUrl.Text;
string iface = txtInterface.Text;
string method = txtMethod.Text;
Dictionary<string, string> parms = StringToDictionary(txtParameters.Text);
Dictionary<string, string> result = CallSoapMethod(url, iface, method, parms);
txtResult.Text = DictionaryToString(result);
}
catch (Exception ex)
{
StringBuilder sbException = new StringBuilder();
while(ex != null)
{
sbException.AppendFormat("{0}\r\n{1}\r\n\r\n", ex.Message, ex.StackTrace);
ex = ex.InnerException;
}
txtResult.Text = sbException.ToString();
}
}
/// <summary>
/// Deseria una cadena a un diccionario string,string
/// </summary>
/// <param name="str">The STR.</param>
/// <returns></returns>
/// <author>VAR</author>
public static Dictionary<string, string> StringToDictionary(string str)
{
var dic = new Dictionary<string, string>();
List<string> pairs = SplitUnscaped(str, ',');
foreach (string pair in pairs)
{
List<string> values = SplitUnscaped(pair, ':');
if (values.Count < 2) continue;
string key = values[0].Replace("\\:", ":").Replace("\\,", ",");
string val = values[1].Replace("\\:", ":").Replace("\\,", ",");
dic.Add(key, val);
}
return dic;
}
/// <summary>
/// Serializa un diccionario string,string a una cadena.
/// </summary>
/// <param name="dic">The dic.</param>
/// <returns></returns>
/// <author>VAR</author>
public static string DictionaryToString(Dictionary<string, string> dic)
{
var sb = new StringBuilder();
foreach (KeyValuePair<string, string> entrada in dic)
{
string sKey = entrada.Key.Replace(":", "\\:").Replace(",", "\\,");
string sVal = entrada.Value.Replace(":", "\\:").Replace(",", "\\,");
sb.AppendFormat("{0}:{1},", sKey, sVal);
}
return sb.ToString();
}
/// <summary>
/// Parte una cadena usando un caracter, evitando usar las ocurrencias escapadas con '\\'
/// </summary>
/// <param name="str">The STR.</param>
/// <param name="splitter">The splitter.</param>
/// <returns></returns>
/// <author>VAR</author>
public static List<string> SplitUnscaped(string str, char splitter)
{
var strs = new List<string>();
int j, i;
int n = str.Length;
for (j = 0, i = 0; i < n; i++)
{
if (str[i] == '\\') i++;
else if (str[i] == splitter)
{
strs.Add(str.Substring(j, i - j));
j = i + 1;
}
}
if (i >= j) strs.Add(str.Substring(j, n - j));
return strs;
}
/// <summary>
/// Llama a un metodo SOAP. Esto requiere que el binding del servicio WCF sea de tipo "basicHttpBinding"
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="iface">The iface.</param>
/// <param name="method">The method.</param>
/// <param name="parms">The parms.</param>
/// <returns></returns>
/// <date>12/05/2014</date>
/// <author>VAR</author>
public static Dictionary<string, string> CallSoapMethod(string url, string iface, string method, Dictionary<string, string> parms)
{
// Los servicios SOAP se llaman siempre a traves de HTTP.
if (url.ToLower().StartsWith("https://"))
{
url = string.Format("http://{0}", url.Substring("https://".Length));
}
// Construir peticion
var sbData = new StringBuilder();
sbData.AppendFormat("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
sbData.AppendFormat("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n");
sbData.AppendFormat("<s:Body>\n");
sbData.AppendFormat("<{0} xmlns=\"http://tempuri.org/\">\n", method);
foreach (KeyValuePair<string, string> parm in parms)
{
sbData.AppendFormat("<{0}>{1}</{0}>\n", parm.Key, parm.Value);
// FIXME: Accept null values
//sbData.AppendFormat("<{0} i:nil=\"true\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" />\n", parm.Key);
}
sbData.AppendFormat("</{0}>\n", method);
sbData.AppendFormat("</s:Body>\n");
sbData.AppendFormat("</s:Envelope>\n");
byte[] postData = Encoding.UTF8.GetBytes(sbData.ToString());
// Realizar peticion
var client = new System.Net.WebClient();
client.Headers.Add("Accept", "text/xml");
client.Headers.Add("Accept-Charset", "UTF-8");
client.Headers.Add("Content-Type", "text/xml; charset=UTF-8");
client.Headers.Add("SOAPAction", string.Format("\"{0}/{1}/{2}\"", "http://tempuri.org", iface, method));
byte[] data;
try
{
data = client.UploadData(url, "POST", postData);
}
catch (Exception ex)
{
throw new Exception(string.Format("Failure calling SoapService: URL: {0}", url), ex);
}
string strData = System.Text.Encoding.UTF8.GetString(data);
var strReader = new StringReader(strData);
var xmlReader = new XmlTextReader(strReader);
// Parsear resultado
Dictionary<string, string> resultObject = new Dictionary<string, string>();
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element)
{
String name = xmlReader.Name;
if (name.Contains(":"))
{
name = name.Split(':')[1];
}
resultObject.Add(name, xmlReader.ReadString());
}
}
return resultObject;
}
}
}

View File

@@ -38,15 +38,14 @@
this.pnlCover1 = new VAR.Toolbox.UI.PnlCover();
this.niTray = new System.Windows.Forms.NotifyIcon(this.components);
this.btnExit = new System.Windows.Forms.Button();
this.btnTestSoapService = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnBase64
//
this.btnBase64.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnBase64.Location = new System.Drawing.Point(9, 52);
this.btnBase64.Name = "btnBase64";
this.btnBase64.Size = new System.Drawing.Size(159, 34);
this.btnBase64.Size = new System.Drawing.Size(165, 34);
this.btnBase64.TabIndex = 0;
this.btnBase64.Text = "Base64";
this.btnBase64.UseVisualStyleBackColor = true;
@@ -54,11 +53,9 @@
//
// btnProxyCmd
//
this.btnProxyCmd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnProxyCmd.Location = new System.Drawing.Point(9, 92);
this.btnProxyCmd.Name = "btnProxyCmd";
this.btnProxyCmd.Size = new System.Drawing.Size(159, 36);
this.btnProxyCmd.Size = new System.Drawing.Size(165, 36);
this.btnProxyCmd.TabIndex = 1;
this.btnProxyCmd.Text = "ProxyCmd";
this.btnProxyCmd.UseVisualStyleBackColor = true;
@@ -66,11 +63,9 @@
//
// btnWebcam
//
this.btnWebcam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnWebcam.Location = new System.Drawing.Point(9, 135);
this.btnWebcam.Name = "btnWebcam";
this.btnWebcam.Size = new System.Drawing.Size(159, 36);
this.btnWebcam.Size = new System.Drawing.Size(165, 36);
this.btnWebcam.TabIndex = 2;
this.btnWebcam.Text = "Webcam";
this.btnWebcam.UseVisualStyleBackColor = true;
@@ -78,12 +73,10 @@
//
// btnTunnelTCP
//
this.btnTunnelTCP.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnTunnelTCP.Location = new System.Drawing.Point(9, 175);
this.btnTunnelTCP.Margin = new System.Windows.Forms.Padding(2);
this.btnTunnelTCP.Name = "btnTunnelTCP";
this.btnTunnelTCP.Size = new System.Drawing.Size(159, 36);
this.btnTunnelTCP.Size = new System.Drawing.Size(165, 36);
this.btnTunnelTCP.TabIndex = 5;
this.btnTunnelTCP.Text = "TunnelTCP";
this.btnTunnelTCP.UseVisualStyleBackColor = true;
@@ -97,29 +90,25 @@
this.lblToolbox.Location = new System.Drawing.Point(9, 9);
this.lblToolbox.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblToolbox.Name = "lblToolbox";
this.lblToolbox.Size = new System.Drawing.Size(159, 40);
this.lblToolbox.Size = new System.Drawing.Size(336, 40);
this.lblToolbox.TabIndex = 6;
this.lblToolbox.Text = "Toolbox";
this.lblToolbox.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// pnlSuspension1
//
this.pnlSuspension1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pnlSuspension1.Location = new System.Drawing.Point(10, 323);
this.pnlSuspension1.Location = new System.Drawing.Point(180, 241);
this.pnlSuspension1.Margin = new System.Windows.Forms.Padding(1);
this.pnlSuspension1.Name = "pnlSuspension1";
this.pnlSuspension1.Size = new System.Drawing.Size(155, 114);
this.pnlSuspension1.Size = new System.Drawing.Size(165, 114);
this.pnlSuspension1.TabIndex = 4;
//
// pnlCover1
//
this.pnlCover1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pnlCover1.Location = new System.Drawing.Point(10, 225);
this.pnlCover1.Location = new System.Drawing.Point(12, 241);
this.pnlCover1.Margin = new System.Windows.Forms.Padding(1);
this.pnlCover1.Name = "pnlCover1";
this.pnlCover1.Size = new System.Drawing.Size(155, 96);
this.pnlCover1.Size = new System.Drawing.Size(162, 114);
this.pnlCover1.TabIndex = 3;
//
// niTray
@@ -130,21 +119,30 @@
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Location = new System.Drawing.Point(12, 441);
this.btnExit.Location = new System.Drawing.Point(12, 359);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(152, 29);
this.btnExit.Size = new System.Drawing.Size(333, 29);
this.btnExit.TabIndex = 7;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnTestSoapService
//
this.btnTestSoapService.Location = new System.Drawing.Point(180, 52);
this.btnTestSoapService.Name = "btnTestSoapService";
this.btnTestSoapService.Size = new System.Drawing.Size(165, 34);
this.btnTestSoapService.TabIndex = 8;
this.btnTestSoapService.Text = "TestSoapService";
this.btnTestSoapService.UseVisualStyleBackColor = true;
this.btnTestSoapService.Click += new System.EventHandler(this.btnTestSoapService_Click);
//
// FrmToolbox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(175, 482);
this.ClientSize = new System.Drawing.Size(352, 400);
this.Controls.Add(this.btnTestSoapService);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.lblToolbox);
this.Controls.Add(this.btnTunnelTCP);
@@ -175,6 +173,7 @@
private System.Windows.Forms.Label lblToolbox;
private System.Windows.Forms.NotifyIcon niTray;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnTestSoapService;
}
}

View File

@@ -95,6 +95,11 @@ namespace VAR.Toolbox.UI
CreateWindow(typeof(FrmTunnelTCP));
}
private void btnTestSoapService_Click(object sender, EventArgs e)
{
CreateWindow(typeof(FrmTestSoapService));
}
#endregion UI events
#region Window handling
@@ -169,5 +174,6 @@ namespace VAR.Toolbox.UI
}
#endregion Window handling
}
}

View File

@@ -106,6 +106,12 @@
<Compile Include="UI\FrmProxyCmd.Designer.cs">
<DependentUpon>FrmProxyCmd.cs</DependentUpon>
</Compile>
<Compile Include="UI\FrmTestSoapService.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\FrmTestSoapService.Designer.cs">
<DependentUpon>FrmTestSoapService.cs</DependentUpon>
</Compile>
<Compile Include="UI\FrmTunnelTCP.cs">
<SubType>Form</SubType>
</Compile>