Solved

How to generate XML request and process response

Posted on 2013-06-10
3
418 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net 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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…

821 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