Classic ASP code to C# equivilant

Posted on 2009-05-20
Last Modified: 2013-11-07
I need help translating the following code to the equivilant in ASP.NET C#.  It is for use with Paypal payflow pro to provide a simple interface to submit transactions.  I'm not looking for alternatives, just the translation equivilant.  My main problem is the Server.CreateObject("WinHttp.WinHttpRequest.5.1")  Thanks in advance.

' This work product is provided "AS IS" and without warranty. 


'Please refer to the posting regarding the HTTPS Interface on the PayPal Developer's

'Forum for the Payflow Gateway.  Go to and "Jump to" 

'Payflow Gateway.


'You will also need to reference the Payflow Pro Developer's Guide are that available

'from the Integration Center at

'Things you should implement are:


'1. Check for DUPLICATE transaction and react accordingly.

'2. Build in some re-try logic in case you do not receive a response.  You will

'   need to take into consideration the Request ID. See the HTTPS Interface posting for

'   more information on the Request ID and DUPLICATE response.

'Define the Gateway URL

'Do not use the older host URls of or

if request.form("GHostURL") = 0 then

	GatewayHost = ""

elseif request.form("GHostURL") = 1 then

	GatewayHost = ""

end if

'Put in your login information here

Password = "xxxxx"

UserID = "xxxxxx"

VendorID = "xxxxxx"

PartnerID = "xxxxxx"

' Start out declaring our variables.

Dim objWinHttp

Dim strHTML

Dim parmList

Dim requestID

' Need to generate a unique id for the request id

requestID = generateRequestID(32)

'Build the parameter list


'This a very, very basic implementation to just how how you can post data.  What data 

'you decide to send and how your react to the response is a business decision that you

'must make.

parmList = "TENDER=C"

parmList = parmList + "&ACCT=" + request.form("cardNum") 

parmList = parmList + "&PWD=" & Password

parmList = parmList + "&USER=" & UserID

parmList = parmList + "&VENDOR=" & VendorID

parmList = parmList + "&PARTNER=" & PartnerID

parmList = parmList + "&EXPDATE=" + request.form("cardExp")

parmList = parmList + "&AMT=" + request.form("amount")

parmList = parmList + "&TRXTYPE=" + request.form("TransactType")

parmList = parmList + "&STREET=" + request.form("StreetAddress")

parmList = parmList + "&ZIP=" + request.form("ZipCode")

'original v3 SDK line, replaced with WinHttp

' create the PNCOMClient component

'Set client = Server.CreateObject("PFProCOMControl.PFProCOMControl.1")

'Open Session

Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")

' Full Docs:



' If you have trouble or are getting connection errors,

' try using the proxycfg.exe tool.

' Here we get the request ready to be sent.

' First 2 parameters indicate method and URL.

' The third is optional and indicates whether or not to

' open the request in asyncronous mode (wait for a response

' or not).  The default is False = syncronous = wait.

' Syntax:

'original v3 SDK line, replaced with WinHttp Open statement

'Ctx1 = client.CreateContext("", 443, 30, "", 0, "", "")

objWinHttp.Open "POST", GatewayHost, False

'Build the headers


'The required headers are Content-Type, X-VPS-Timeout and X-VPS-Request-ID.  All other headers are for

'your use and you'd populate them based on your environment.


objWinHttp.setRequestHeader "Content-Type", "text/namevalue"  ' for XML, use text/xml

'objWinHttp.SetRequestHeader "Host", ""   ' your website

objWinHttp.SetRequestHeader "X-VPS-Timeout", "30"

'objWinHttp.SetRequestHeader "X-VPS-VIT-Client-Architecture", "x86"  ' set to your environment

'objWinHttp.SetRequestHeader "X-VPS-VIT-Client-Type", "ASP/Classic"

'objWinHttp.SetRequestHeader "X-VPS-VIT-Client-Version", "0.0.1"     ' your application version

'objWinHttp.SetRequestHeader "X-VPS-VIT-Integration-Product", "Homegrown"   ' your application 

'objWinHttp.SetRequestHeader "X-VPS-VIT-Integration-Version", "0.0.1"

'objWinHttp.SetRequestHeader "X-VPS-VIT-OS-Name", "windows"      ' your OS

'objWinHttp.SetRequestHeader "X-VPS-VIT-OS-Version", "2002_SP2"  ' your OS version

objWinHttp.SetRequestHeader "X-VPS-Request-ID", requestID

'Send Parameter List

'original v3 SDK line, replaced with WinHttp Send

'curString = client.SubmitTransaction(Ctx1, parmList, Len(parmList))

objWinHttp.Send parmList

' Print out the request status:

Response.Write "Status: " & objWinHttp.Status & " " _

	& objWinHttp.StatusText & "<br />"

' Get the text of the response.

transResponse = objWinHttp.ResponseText

'original v3 SDK line, replaced with Nothing statement

'client.DestroyContext (Ctx1)

' Trash our object now that we are finished with it.

Set objWinHttp = Nothing

Open in new window

Question by:Paulconsulting

Accepted Solution

rdogmartin earned 500 total points
Comment Utility
This isn't the translation you asked for, but I think it will help. It is code I use during a PayPal payment notification. I construct an HTTP post and then read the HTTP response back as a string. The HttpWebRequest object has a Headers property for setting the request headers.

private bool ValidateNotification()


	const string PAYPAL_URL = "";

	HttpWebRequest req = (HttpWebRequest)WebRequest.Create(PAYPAL_URL);

	//Set values for the request back

	req.Method = "POST";

	req.ContentType = "application/x-www-form-urlencoded";

	byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);

	string strRequest = System.Text.Encoding.ASCII.GetString(param);

	strRequest += "&cmd=_notify-validate";

	req.ContentLength = strRequest.Length;

	//Send the request to PayPal and get the response

	StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);



	StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());

	string strResponse = streamIn.ReadToEnd();


	return (strResponse == "VERIFIED");


Open in new window


Author Closing Comment

Comment Utility
Thanks, i ended up using a different dll to solve the problem.  Thanks for your help.

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now