Solved

How to generate XML request and process response

Posted on 2013-06-10
3
416 Views
Last Modified: 2013-06-29
Hi Experts, can someone show me how I can generate a web request in ASP.NET VB and process the response for the data below. I am not sure how to generate the request and send it to the remote server.

Sample Request (XML)
GET https://sandbox.tchng.com/test_parect/api/v1/gettransaction.xml?productid=21&transactionreference=8421941122&amount=300000 HTTP/1.1
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.239)
Hash: F6FF2E22F99D93DDDA52D71811FD92B3A71FA1968A66216E0D310DAD

Open in new window


Sample Response (XML)
HTTP/1.0 200 OK
Date: Tue, 30 Oct 2012 16:20:56 GMT
Content-Type: application/xml; charset=utf-8
Content-Length: 552
<TransactionQueryResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><ResponseCode>00</ResponseCode><ResponseDescription>Approved Successful</ResponseDescription><Amount>300000</Amount><CardNumber>6055</CardNumber><MerchantReference>8421941122</MerchantReference><PaymentReference>ZIB|WEB|VNA|15-10-2012|015933</PaymentReference><RetrievalReferenceNumber>000000538268</RetrievalReferenceNumber><SplitAccounts /><TransactionDate>2012-10-15T11:07:54.547</TransactionDate></TransactionQueryResponse>

Open in new window

0
Comment
Question by:takwirirar
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 39234470
0
 
LVL 1

Accepted Solution

by:
takwirirar earned 0 total points
ID: 39274079
I am sorry that link doesnt seem to have the information I require.

This is what I was looking for

' Create a request for the URL. 
Dim request As WebRequest = _
WebRequest.Create("urlforpage")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
request.Headers.Add("customheader", "headertext")

' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)

'read the XML response
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(reader.ReadToEnd())

Dim ResponseCode As XmlElement = doc.DocumentElement("YourElement")
' Retrieve the value from the ResponseCode element.
Dim responseValue As String = YourElement.InnerXml
'Display the values you require
resp.Text = responseValue


' Clean up the streams and the response.
reader.Close()
response.Close()

Open in new window

0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 39286449
Other Expert comment was not suffient. After looking around I found the answer.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Blog Template 2 37
Test ddwrt:UserLookup 1 53
Please explain "Multi-Tenant Services" 5 65
SQL Login 17 40
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

21 Experts available now in Live!

Get 1:1 Help Now