Home arrow ASP arrow Page 3 - HTTP Tunneling Revealed: Part 2/3
ASP

HTTP Tunneling Revealed: Part 2/3


In part 2 of this article Adnan shows us how to fake a web service using XMLHTTP in ASP, how to handle HTTPS authentication via ServerXMLHTTP and more.

Author Info:
By: Adnan Masood
Rating: 5 stars5 stars5 stars5 stars5 stars / 27
October 22, 2002
TABLE OF CONTENTS:
  1. · HTTP Tunneling Revealed: Part 2/3
  2. · Forcing Downloads
  3. · Invoking a Web Service Using Only XMLHTTP
  4. · Implementation in .NET Using System.Net.WebClient
  5. · Conclusion

print this article
SEARCH DEVARTICLES

HTTP Tunneling Revealed: Part 2/3 - Invoking a Web Service Using Only XMLHTTP
(Page 3 of 5 )

In this article I'm more focused on practical implementation of web services, but for those who needs details, IBM's web services architect overview is a good resource.

XMethods, as its name suggest, is a library for methods implemented via Web Services. "This site is a "virtual laboratory" for developers , listing publicly available web services and showcasing new ways this technology can be applied".

As they say, laughter is the best Medicine!. I have found an interesting web service for jokes by Innerpressfact (http://interpressfact.net/webservices/) that accepts a SOAP envelope with joke category ID in it and returns a random joke.

This web service is listed on XMethods here.

Now, down to the business! How can we implement this web service using traditional XMLHTTP? As you learned above, SOAP is a protocol to exchange information, period. It has a concrete format to exchange data over the wire. It provides the namespace, the XML schema and the required parameters to invoke the web service and read the resultant string.

The SOAP invocation string comprises of the getjoke name space:

<getJoke xmlns=""http://interpressfact.net/webservices/"">"

... the required parameter category in the DOM:

<Category>category </Category>

... and last but not least, setting the headers for method invocation:
  • Setting request as the SOAP request for POST
  • Assigning a HOST for SoapServer
  • Setting the content-type as text/XML
  • Encoding the request into utf-8 format
  • Setting the SOAPAction for the invocation URI
xmlhttp.Open "POST", "http://" & SoapServer & SoapPath, False
xmlhttp.setRequestHeader "Man", "POST " & SoapPath & " HTTP/1.1"
xmlhttp.setRequestHeader "Host", SoapServer
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SOAPAction", http://interpressfact.net/webservices/getJoke

xmlhttp.send(strSoap)


What we receive as XML is:

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://interpressfact.net/webservices/">Q: How do you get a lawyer out of a tree? A: Cut the rope.</string>


The XMLDOM function, xml.selectSingleNode returns the joke as the end result. The complete listing explaining the invocation is shown below:

<%' [ Interpressfact 2002 ]

Function getJoke(category)
Const SoapServer = "interpressfact.net"
Const SoapPath = "/webservices/getJoke.asmx"
Dim xmlhttp, strSoap
set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
'Create Soap request
strSoap = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<getJoke xmlns=""http://interpressfact.net/webservices/"">" & _
"<Category>" & category & "</Category>" & _
"</getJoke>" & _
"</soap:Body>" & _
"</soap:Envelope>"

'Send Soap Request
xmlhttp.Open "POST", "http://" & SoapServer & SoapPath, False
xmlhttp.setRequestHeader "Man", "POST " & SoapPath & " HTTP/1.1"
xmlhttp.setRequestHeader "Host", SoapServer
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SOAPAction", http://interpressfact.net/webservices/getJoke
xmlhttp.send(strSoap)
If xmlhttp.Status = 200 Then ' Response from server was success
getJoke = xmlhttp.responseText
Else ' Response from server failed
getJoke = ("Temporary Error.")
End If
set xmlhttp = nothing
End Function
If request("category") <> "" then
Dim Joke
dim xml : set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
'Load Xml From ResponseText of the getJoke function
xml.loadxml(getJoke(request("category")))
' Select a Single node from ResponseText
dim oNode : set oNode = xml.selectSingleNode("soap:Envelope/soap:Body/getJokeResponse/getJokeResult")
'Joke variable now contains the Received Joke from the getJoke webservice
Joke = oNode.text
set xml = nothing
end if
%>
<h1> Joke from interpressfact </h1>
<%=joke%>


The Interpressfact getJoke Webservice in Action

You can invoke virtually any SOAP based web service via this mechanism, although the parameters need to be changed of course.
blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials