Manual SOAP Request (w/o Service Reference)

Costas

Administrator
Staff member
reference - https://www.roelvanlisdonk.nl/?p=1893

1-Download and install fiddle (http://www.telerik.com/fiddler) (enable - Tools > Fiddler Options > HTTPS tag > Decrypt HTTPS trafic)
2-Create a new desktop application (note ASP.NET call cant be traced, because running under different user account, http://www.telerik.com/blogs/capturing-traffic-from-.net-services-with-fiddler)
3-Fire up VS, Add the WSDL url aka hxxps://paycenter.piraeusbank.gr/services/tickets/issuer.asmx via PRJ (r-click click) > Add Service Reference
snap009.png

4-edit your app.config
remark customBinding tag and customBinding endpoint
5-on your desktop application form paste :

JavaScript:
//used to calculate md5 from password
public string CalculateMD5Hash(string input)
{
	// step 1, calculate MD5 hash from input
	MD5 md5 = System.Security.Cryptography.MD5.Create();
	byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
	byte[] hash = md5.ComputeHash(inputBytes);

	// step 2, convert byte array to hex string
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < hash.Length; i++)
	{
		sb.Append(hash[i].ToString("X2"));
	}
	return sb.ToString().ToLower();
}

6-add a button to form, on button event write

JavaScript:
private void button1_Click(object sender, EventArgs e)
{
	string ret_MerchantReference = "7"; //your order_id here

	ServiceReference1.TicketRequest x = new ServiceReference1.TicketRequest();

	x.AcquirerId = 1;
	x.MerchantId = 2;
	x.PosId = 3;
	x.Username = "3";
	x.Password = CalculateMD5Hash("4"); // md5 - "4";
	x.CurrencyCode = 978; //978-euro
	x.Amount = 10;
	x.MerchantReference = ret_MerchantReference;

	ServiceReference1.TicketingServiceSoapClient t = new ServiceReference1.TicketingServiceSoapClient();
	ServiceReference1.TicketResponse y = t.IssueNewTicket(x);
	Console.WriteLine(y.ResultDescription);
}

7-now, using fiddle, sniff the request
snap006.png


snap007.png


snap008.png


formatted :

JavaScript:
//test
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<IssueNewTicket xmlns="http://piraeusbank.gr/paycenter/redirection">
		<Request>
			<Username>3</Username>
			
x</Password>
			<MerchantId>2</MerchantId>
			
3</PosId>
			<AcquirerId>3</AcquirerId>
			<MerchantReference>7</MerchantReference>
			<ExpirePreauth>0</ExpirePreauth>
			<Amount>10</Amount>
			<CurrencyCode>978</CurrencyCode>
			<Installments>0</Installments>
			<Bnpl>0</Bnpl>
			<RequestType>00</RequestType>
		</Request>
	</IssueNewTicket>
</s:Body></s:Envelope>

8-create a new PRJ! following the https://www.roelvanlisdonk.nl/?p=1893 directions
9-Paste&Compile&Execute :

JavaScript:
private void button1_Click(object sender, EventArgs e)
{
	Execute();
}

///
/// Execute a Soap WebService call
/// 

public void Execute()
{
	HttpWebRequest request = CreateWebRequest();
	XmlDocument soapEnvelopeXml = new XmlDocument();
	soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                                <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
                                <s:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                                    <IssueNewTicket xmlns=""http://piraeusbank.gr/paycenter/redirection"">
                                        <Request>
                                            <Username>3</Username>
                                            
x</Password>
                                            <MerchantId>2</MerchantId>
                                            
3</PosId>
                                            <AcquirerId>3</AcquirerId>
                                            <MerchantReference>7</MerchantReference>
                                            <ExpirePreauth>0</ExpirePreauth>
                                            <Amount>10</Amount>
                                            <CurrencyCode>978</CurrencyCode>
                                            <Installments>0</Installments>
                                            <Bnpl>0</Bnpl>
                                            <RequestType>00</RequestType>
                                        </Request>
                                    </IssueNewTicket>
                                </s:Body></s:Envelope>");

	using (Stream stream = request.GetRequestStream())
	{
		soapEnvelopeXml.Save(stream);
	}

	using (WebResponse response = request.GetResponse())
	{
		using (StreamReader rd = new StreamReader(response.GetResponseStream()))
		{
			string soapResult = rd.ReadToEnd();
			Console.WriteLine(soapResult);
		}
	}
}

///
/// Create a soap webrequest to [Url]
/// 

/// 
public HttpWebRequest CreateWebRequest()
{
	HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx");
	webRequest.Headers.Add(@"SOAP:Action");
	webRequest.ContentType = "text/xml;charset=\"utf-8\"";
	webRequest.Accept = "text/xml";
	webRequest.Method = "POST";
	return webRequest;
}

the result is :

JavaScript:
//test
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <IssueNewTicketResponse xmlns="http://piraeusbank.gr/paycenter/redirection">
            <IssueNewTicketResult>
                <ResultCode>1041</ResultCode>
                <ResultDescription>   [SRID: 59420043] Invalid IP address.</ResultDescription>[TR]
                <Timestamp>2016-02-02T10:35:00.3210429+02:00</Timestamp>
                <MinutesToExpiration>
                0</MinutesToExpiration>
        </IssueNewTicketResult>
        </IssueNewTicketResponse>
    </soap:Body>
</soap:Envelope>

time to make the ASP.NET flavor on server, because server IP, white listed to bank!

running the same code on aspx the response was :

JavaScript:
//test
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:body>
    <issuenewticketresponse xmlns="http://piraeusbank.gr/paycenter/redirection">
        <issuenewticketresult>
            <resultcode>0</resultcode>
            <resultdescription>
                [TR]2xxxx3</tranticket>
                <timestamp>2016-01-01T11:53:00.3473139+02:00</timestamp>
                <minutestoexpiration>10</minutestoexpiration>
            </resultdescription>
        </issuenewticketresult>
    </issuenewticketresponse>
</soap:body>
</soap:envelope>

now we have to read the tranticket from SOAP response^ and submit a form to gateway

JavaScript:
string resp_tranticket;
var doc = XDocument.Parse(soapResult);

XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/";//Envelop namespace s
XNamespace bhr = "http://piraeusbank.gr/paycenter/redirection";//Response namespace

foreach (var itm in doc.Descendants(s + "Body").Descendants(bhr + "IssueNewTicketResponse").Descendants(bhr + "IssueNewTicketResult").Descendants(bhr + "TranTicket"))
{
   resp_tranticket = itm.Value.ToString();
   MerchantReference.Value = soapResult; //set the resp_tranticket value to #MerchantReference HTML input#
}

then, submit the HTML form!

JavaScript:
//test
<form action="https://paycenter.piraeusbank.gr/redirection/pay.aspx" method="POST" runat="server">
    <input name="AcquirerId" type="text" value="1" /> <br/>
    <input name="MerchantId" type="text" value="2" /> <br/>
    <input name="PosId" type="text" value="3" /> <br/>
    <input name="User" type="text" value="4" /> <br/>
    <input name="LanguageCode" type ="text"  value="el-GR" /> <br/>
    <input id="MerchantReference" name="MerchantReference" runat="server" type="text" value="0" /> <br/>
    <input name="ParamBackLink" type="text" value="p1=v1&amp;p2=v2" /> 
</form>

---

complete code debug :

JavaScript:
//default.aspx - HTML
<form action="https://paycenter.piraeusbank.gr/redirection/pay.aspx" method="POST" runat="server">
        <input name="AcquirerId" type="text" value="1" /> <br/>
        <input name="MerchantId" type="text" value="2" /> <br/>
        <input name="PosId" type="text" value="3" /> <br/>
        <input name="User" type="text" value="4" /> <br/>
        <input name="LanguageCode" type ="text"  value="el-GR" /> <br/>
        <input id="MerchantReference" name="MerchantReference" runat="server" type="text" value="0" /> <br/>
        <input name="ParamBackLink" type="text" value="p1=v1&amp;p2=v2" /> 
</form> 
 
//default.aspx.cs - code behind
protected void Page_Load(object sender, EventArgs e)
{
    Execute();
}
 
/// <summary>
/// Execute a Soap WebService call
/// </summary>
public void Execute()
{
    HttpWebRequest request = CreateWebRequest();
    XmlDocument soapEnvelopeXml = new XmlDocument();
    soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                                <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
                                <s:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                                    <IssueNewTicket xmlns=""http://piraeusbank.gr/paycenter/redirection"">
                                        <Request>
                                            <Username>1</Username>
                                            
2</Password>
                                            <MerchantId>3</MerchantId>
                                            
4</PosId>
                                            <AcquirerId>5</AcquirerId>
                                            <MerchantReference>6</MerchantReference>
                                            <ExpirePreauth>0</ExpirePreauth>
                                            <Amount>10</Amount>
                                            <CurrencyCode>978</CurrencyCode>
                                            <Installments>0</Installments>
                                            <Bnpl>0</Bnpl>
                                            <RequestType>00</RequestType>
                                        </Request>
                                    </IssueNewTicket>
                                </s:Body></s:Envelope>");
 
    using (Stream stream = request.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }
 
    using (WebResponse response = request.GetResponse())
    {
        using (StreamReader rd = new StreamReader(response.GetResponseStream()))
        {
            string soapResult = rd.ReadToEnd();
            Console.WriteLine(soapResult);
 
            string resp_tranticket;
            var doc = XDocument.Parse(soapResult);
 
            XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/";//Envelop namespace s
            XNamespace bhr = "http://piraeusbank.gr/paycenter/redirection";//Response namespace
 
            foreach (var itm in doc.Descendants(s + "Body").Descendants(bhr + "IssueNewTicketResponse").Descendants(bhr + "IssueNewTicketResult").Descendants(bhr + "TranTicket"))
            {
                resp_tranticket = itm.Value.ToString();
                MerchantReference.Value = resp_tranticket; //set the resp_tranticket value to #MerchantReference HTML input#
                submit_form();
            }
 
 
        }
    }
}
 
/// <summary>
/// Create a soap webrequest to [Url]
/// </summary>
/// <returns></returns>
public HttpWebRequest CreateWebRequest()
{
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx");
    webRequest.Headers.Add(@"SOAP:Action");
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    return webRequest;
}
 
private void submit_form()
{
    string formID = "form1";
    //Build the JavaScript which will do the Posting operation.
    StringBuilder strScript = new StringBuilder();
    strScript.Append("<script language='javascript']");
    strScript.Append("var v" + formID + " = document.forms[0];");
    strScript.Append("v" + formID + ".submit();");
    strScript.Append("</script>");
 
    //Return the form and the script concatenated. (The order is important, Form then JavaScript)
    this.Page.Controls.Add(new LiteralControl(strScript.ToString()));
}


complete code - production

JavaScript:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Linq" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Xml" %>
 
 
<%@ Page Language="C#" AutoEventWireup="true" %>
 
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
 
 
    <script runat="server">
 
        string AcquirerId = String.Empty;           //Το id του acquirer.
        string MerchantId = String.Empty;           //Ο κωδικός εμπόρου.
        string PosId = String.Empty;                //Ο κωδικός τερματικού.
         
        string orderId = String.Empty;
        string action = "https://paycenter.piraeusbank.gr/redirection/pay.aspx";
 
 
        //string trType = String.Empty;
        //string confirmUrl = String.Empty;
        //string cancelUrl = String.Empty;
 
        string User = String.Empty;        
        string Password = String.Empty;
        string RequestType = String.Empty;
        string CurrencyCode = String.Empty;
 
        string Amount = String.Empty;
        string Installments = String.Empty;
        string ExpirePreauth = String.Empty;
        string Bnpl = String.Empty;
 
                 //Όνομα χρήστη.
        string LanguageCode = "el-GR";              //Ο κωδικός στην οποία θα εμφανίζεται η σελίδα πληρωμής
        string ParamBackLink = "p1=v1&amp;p2=v2";       //Link όταν ο χρήστης πατήσει Ακύρωση 
        string MerchantReference = String.Empty;    //Ο κωδικός αναφοράς συναλλαγής
         
        string soapResult = String.Empty;
         
        protected void Page_Load(object sender, EventArgs e)
        {
            AcquirerId = "1";
            MerchantId = "2";
            PosId = "3";
            User = "4";
            Password = "5"; // md5 of the password, you got by bank
            AcquirerId = "6";
            ExpirePreauth = "0";
            Amount = "10";
            CurrencyCode = "7";
            Installments = "0";
            RequestType = "00";
            Bnpl = "0";
 
            orderId = "80"; 
                 
            Execute();
        }
 
        /// <summary>
        /// Execute a Soap WebService call
        /// </summary>
        public void Execute()
        {
            HttpWebRequest request = CreateWebRequest();
            XmlDocument soapEnvelopeXml = new XmlDocument();
            soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                                        <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
                                        <s:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                                        <IssueNewTicket xmlns=""http://piraeusbank.gr/paycenter/redirection"">
                                            <Request>
                                                <Username>" + User + "</Username>" +
                                                "
" + Password + "</Password>" +
                                                "<MerchantId>" + MerchantId + "</MerchantId>" +
                                                "
" + PosId + "</PosId>" +
                                                "<AcquirerId>" + AcquirerId + "</AcquirerId>" +
                                                "<MerchantReference>" + orderId + "</MerchantReference>" +
                                                "<ExpirePreauth>" + ExpirePreauth + "</ExpirePreauth>" +
                                                "<Amount>" + Amount + "</Amount>" +
                                                "<CurrencyCode>" + CurrencyCode + "</CurrencyCode>" +
                                                "<Installments>" + Installments + "</Installments>" +
                                                "<RequestType>" + RequestType + "</RequestType>" +
                                                "<Bnpl>" + Bnpl + "</Bnpl>" +
                                            "</Request>" +
                                        "</IssueNewTicket>" +
                                    "</s:Body></s:Envelope>");
 
            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
 
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();
                    Console.WriteLine(soapResult);
 
                    string resp_tranticket;
                    var doc = XDocument.Parse(soapResult);
 
                    XNamespace s = "http://schemas.xmlsoap.org/soap/envelope/";//Envelop namespace s
                    XNamespace bhr = "http://piraeusbank.gr/paycenter/redirection";//Response namespace
 
                    foreach (var itm in doc.Descendants(s + "Body").Descendants(bhr + "IssueNewTicketResponse").Descendants(bhr + "IssueNewTicketResult").Descendants(bhr + "TranTicket"))
                    {
                        resp_tranticket = itm.Value.ToString();
 
                        //set the resp_tranticket value to #MerchantReference HTML input#
                        MerchantReference = resp_tranticket;
                    }
                }
            }
        }
 
        /// <summary>
        /// Create a soap webrequest to [Url]
        /// </summary>
        /// <returns></returns>
        public HttpWebRequest CreateWebRequest()
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx");
            webRequest.Headers.Add(@"SOAP:Action");
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }
     
    </script>
 
    <form action="<%= action %>" method="POST" name="PayformBank" id="PayformBank">
        <input name="AcquirerId" type="text" value="<%= AcquirerId %>" />
        <input name="MerchantId" type="text" value="<%= MerchantId %>" />
        <input name="PosId" type="text" value="<%= PosId %>" />
        <input name="User" type="text" value="<%= User %>" />
        <input name="LanguageCode" type="text" value="<%= LanguageCode %>" />
        <input name="MerchantReference" type="text" value="<%= MerchantReference %>" />
        <input name="ParamBackLink" type="text" value="<%= ParamBackLink %>" />
 
        <%--<input type="submit" value="Check out" />--%>
    </form>
 
    <script type="text/javascript">
        var PayButtonClicked = false;
        function PayClicked() {
            // Check to see if Pay Button has been clicked before
            if (PayButtonClicked) {
                // Message displayed
                alert("Transaction already sent.");
                return false;
            }
            else
                PayButtonClicked = true;
            return true;
        }
 
        document.getElementById('PayformBank').submit();
 
    </script>
</body>
</html>
 
Top