Reputation: 7165
I have to post the value from input fields to my webservice. Searching on the net give no luck at all. I am not allowed to use AJAX/JSon to wrap and post the data, Only through WCF. And I'm stuck with that. Hope someone could help.
HTML FILE:
I remove some fields to minimize the space consumption.
<%@ Page Language="C#" AutoEventWireup="ue" CodeBehind="WebForm1.aspx.cs" Inherits="BasePayment.Client.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//D HTML 4.01 ansitional//EN" "http://www.w3.org//html4/loose.d">
<html>
<body>
<form method="POST" name="frmPayment" action="">
Merchant ID
<input type="text" name="merchantId" value="1546" />
Payment Method
<input type="text" name="pMethod" value="VISA" />
Credit card expiry month - 2 digits.
<input type="text" name="epMonth" value="02" />
Credit card expiry year - 4 digits.
<input type="text" name="epYear" value="2012" />
Credit card number.
<input type="text" name="cardNo" value="4918914107195005" />
Credit Card Verification Code
<input type="text" name="securityCode" value="123" />
Credit card holder name
<input type="text" name="cardHolder" value="Juan Dela Cruz" />
Redirect to a URL upon failed ansaction:
<input type="text" name="failUrl" value="http://www.yahoo.com" />
Remark:
<input type="text" name="remark" value="Other Remarks" />
<input type="submit" value="Submit" id="btnSubmit"/>
</form>
</body>
</html>
WCF:
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using BasePayment.Entities;
using System.ServiceModel.Activation;
namespace BasePayment.WebService
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class PaymentComponent : IPaymentComponent
{
public void SendPayment(PaymentInformation payInfo)
{
PaymentInformation newPayInfo = new PaymentInformation();
/*Validation of input goes here ...
*
*
*
* */
// Then send data.
}
}
}
INTERFACE OF WCF:
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using BasePayment.Entities;
namespace BasePayment.WebService
{
[ServiceContract(Namespace="http://test.com/services/payment")]
public interface IPaymentComponent
{
[OperationContract]
[WebInvoke(UriTemplate="PaymentInfo", Method="POST")]
void SendPayment(PaymentInformation payInfo);
}
}
ENTITY FOR PAYMENT INFO:
I remove some properties to minimize the space consumption.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BasePayment.Entities
{
public class PaymentInformation : IPaymentInformation
{
public PaymentInformation()
{
}
public int ExpiryMonth
{
get;
set;
}
public int ExpiryYear
{
get;
set;
}
public int CreditCardVerificationCode
{
get;
set;
}
public double Amount
{
get;
set;
}
public string Language
{
get;
set;
}
public string CardHolderName
{
get;
set;
}
public string Remark
{
get;
set;
}
}
}
INTERFACE OF ENTITY:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BasePayment.Entities
{
interface IPaymentInformation
{
long CreditCardNumber { get; set; }
long OrderReferenceID { get; set; }
int CurrencyCode { get; set; }
int MerchantID { get; set; }
int ExpiryMonth { get; set; }
int ExpiryYear { get; set; }
int CreditCardVerificationCode { get; set; }
double Amount { get; set; }
string Language { get; set; }
string CardHolderName { get; set; }
string URLUponFailed { get; set; }
string URLUponSuccess { get; set; }
string URLUponError { get; set; }
string Remark { get; set; }
PaymentMethod PaymentMethod { get; set; }
}
}
AND HERE IS THE PREVIEW OF MY PROJECT:
Thanks in advance !!!
Upvotes: 3
Views: 2074
Reputation: 50573
What you could do is post the inputs back to the server side code which in this case would be WebForm1.aspx.cs, what you need to do is set the inputs to runat="server" or use aspx controls like the following:
<asp:TextBox runat="server" id="merchantId" value="1546" />
You would need to do this for all the inputs. Then in the Page load method you could go:
protected void Page_Load(object sender, EventArgs e)
{
if(this.IsPostBack)
{
PaymentInformation newPayInfo = new PaymentInformation();
newPayInfo.MerchantID = merchantId.Text; // to get text
/* Validation of input goes here ... */
// Then send data.
}
}
That means you dont need to use WCF you can just use the page.
Hope this makes sense
Upvotes: 1