asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

The Evolution of Web Services
By Adnan Masood
Rating: 4.2 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    The Internet is not just about making Web sites. It's about the streamlining of business solutions and synergy to provide the seamless enterprise information exchange.

    Sharing information is the basis of enterprise networking architecture, from the legacy of Win32 Internet Extensions (WinInet) to the current range of Web Services. One interesting collection of non-Windows Web Services is maintained by XMethods. XMethods is becoming overwhelmed with the continuity of communication protocol enhancements. This article explains this saga of information exchange progression, using example code and revealing the distributed Electronic Data Interchange (EDI) in detail.

    This article also explains the technological evolution of Web Services; therefore, I found it necessary to explain the underlying technologies. It's a tale of a long journey from Windows' Internet controls to the Web clients of ASP.NET. It explains the evolution of the Simple Object Access Protocol (SOAP) and Web Services, with definitions and examples. First I'll demonstrate the Uniform Resource Identifier (URI) information-exchange process without third-party tools, for example, through archaic Inetctls and reading amazon.com's book reviews with the book's ISBN in the query strings. Inetctls involve an ActiveX component called the Internet Transfer control to connect to other Web servers to do file transfers.

    Later, its modified form XMLHTTP and ServerXMLHTTP will be discussed as more effective tunneling tools. Third-party components such as Christophe Wille's AspTear freeware, Weberie Internet Service's AspHTTP, Dynu System Inc.'s DynuHttp ASP Component, and Flick's Software's OCXHttp and their implementations are the next topic.

    The article will also move towards more sophisticated implementations, such as .NET Web clients and SOAP envelopes, which implement a Web Service from XMethods. In an attempt to be practical, all examples provided are ASPX files developed with .NET Framework with SP2 (Service Pack 2). The diversity of examples will hopefully keep interest high.

    download source code

    The first time I read "HTTP tunneling" as a term was in Karl Moss' "Java Servlets" (McGraw Hill, ISBN 0071351884), but this technology has many different names. HTTP tunneling is also known as distributed EDI, EDI over HTTP-RPC, "grabbing" information from other servers, an external server-side include (SSI), super glue for the Web, sharing information from other web sites, tearing the pages, importing and exporting data over HTTP, GET and POST automation, ripping off Web pages, importing part of pages, or can be even read in simple bulletin board questions as "How can I display CNN.com's headlines on my Web page?"

    It sounds strange, but factually, there was no standard mechanism for such information sharing, and the techniques involved were raw and unreliable, and analogous with stealing information from others. From tracing the tables' beginning and ending via string search operations, or a more sophisticated way, regular expressions, the necessity of having a common sharing standard was strongly expressed by developers. This is what led to the development of SOAP and Web Services.

    Distributed EDI automation has eminent uses. It could be used equally on the Web and desktop for the following:

    • from meta search engines,
    • displaying keyword search results in multiple user interfaces (Uis),
    • spell-checks,
    • newspaper or article references from,
    • image galleries,
    • speeding up dynamic pages (caching),
    • sending SMS,
    • monitoring the Web for new information on subjects,
    • money exchange rates and stock updates,
    • time servers,
    • live auction stats,
    • news tickers,
    • monitoring researches and trends over time,
    • user interfaces in desktop application for Web-based data,
    • anonymizers (server variable spoofing web and application fronts for privacy), etc.

    With the implementation of HTTP 1.0 RFC, GET and POST emerged as two frequently used methods for requests, and the programming emphasis focused on exploiting the power of URIs.


    Figure 1 Defines a simple mechanism of HTTP Request-Response

    Initially, Microsoft's support for tunneling was through the Inet library controls (AKA. Microsoft Internet Transfer Control). Using this tunneling control was quite easy, like other COM components: instantiate, set the properties, and here you go. Besides the basic GET/POST/Head support, few of the internet controls exploiting Winsock include HTTP through proxy (Secure Sockets Layer (SSL) is not permissible through proxy). The AccessType attribute is used to set the proxy, for example

    
    Inet.AccessType = icDirect
    
    
    The Constants values for AccessType are

    • icUseDefault default settings found in the registry to access the Internet
    • icDirect or 1, for example, direct connection to the Internet
    • and 2 or an enumerated icNamedProxy to use the proxy server specified in the Proxy property.

    The Protocol attribute is intuitively simple; it can be set to a numeric value or its enumeration

    • IcDefault = 1
    • icFTP = 2 'FTP. File Transfer Protocol
    • icGopher = 3 'Gopher Const
    • icHTTP = 4 'HTTP. Hypertext Transfer Protocol
    • icHTTPS = 5 'Secure HTTP.

    The RemotePort attribute value can be manually set to the port address (for proxy access); otherwise it is set to 80 by defualt. The RequestTimeOut property can be set for possible delays in downloading time. To assign the URL, there is the URL attribute.

    OpenURL returns the data as a string, which can be assigned and hold a stream of bytes. For instance

    
    resultant = inet.OpenURL()
    
    
    For detailed information on error messages and constants of Internet controls, see Don Hayward of Insight Graphics' useful article at www.insightgraphics.com/reference/ITCRetrieval.htm

    At first glance, this control looks quick and easy to use, but I found it was quite bitter. It crashes often, especially during FTP operations, and eats a lot of CPU cycles during simple operations. Later Microsoft published it at http://wwww.support.microsoft.com as OpenURL Method Bug in Internet Control, and then WinInet Limits Connections per Server, and then finally WinInet Not Supported for Use in Services. While developing an application to load a text file from a UNIX-based FTP site, I found that using the OpenURL method on the Internet Transfer Control for FTP URLs causes a Web server crash and 100 percent CPU utilization.

    Details of its retirement can be found on the following:

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q175179
    http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q238425&
    http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q183110&

    Even with its problems, it was a major tool and was quite publicized by Microsoft for its functionality. It later evolved to XMLHTTP and ServerXMLHTTP. That's why I practically demonstrate below how it can be used to retrieve information from other servers, in this case amazon.com. The URI on amazon.com, if provided with an ISBN, returns a book's details. For example, the URL http://www.amazon.com/exec/obidos/ASIN/0764549529 uses the ISBN of 0764549529, which is the ISBN for a book entitled Java Web Services Programming. This example is for educational purposes only. For commercial usage, one must read the terms and conditions that affiliate programs provide.

    The header prefix "aspcompat=true" makes the .NET page backwards-compatible with classic ASP.

    Listing 1.1: Internet Control Usage
    inetinfo1.aspx

    
    <%@ Page aspcompat=true %> 
    <% dim URL, inet, resultant
    
    '// The URL to download the book information with ISBN 0764549529
    URL = "http://www.amazon.com/exec/obidos/ASIN/0764549529"
    '// Instantiating Inet Control
    inet = Server.CreateObject ("InetCtls.Inet")
    '// timeout adjustment
    inet.RequestTimeOut = 20
    '// Assign the URL 
    inet.Url = URL
    '// let the variable resultant download and hold the file
    resultant = inet.OpenURL()
    Response.write ("<h1> This is an example using InetInfo</h1>")
    response.write (s) 
    %>
    
    

    Figure 1.1 Shows the Microsoft Internet control in action

    Classic ASP doesn't have the rich I/O libraries that are required for generating server requests, or say HTTP "spoofing." For example, pretend that it is just another Web browser asking for information from the site and the solution was to write a component that was not very difficult, but people found it much easier to purchase one of the third-party components designed for this purpose.

    Finding the right time, market space, and venue for commercial COM components that retrieve data from other Web sites through HTTP requests, led ServerObjects, the mega tools and components development company, to launch AspHTTP while AlphaSierraPapa released its AspTear. These tools dwarfed the Internet Control and provided enhanced support and functionality. The later release of XMLHTTP and ServerXMLHTTP gave development a leading edge, but AspHTTP and AspTear already had captured a good market.

    This component allows the generic GET/POST/HEAD documents over HTTP; exposes HTTP response headers; supports transferring requests to a file (including binary transfers); password authentication support, and more. The latest version claims to be 2 to 3 times faster than previous versions. AspHTTP, which supports all major platforms, including Windows 9X, Millennium, NT, and 2000, uses the Winsock API rather than the WinInet API, which documents Microsoft's acknowledged problems discussed earlier. AspHTTP's clients include blue-chip companies like Bank of America, Dialog, UUNET, Trane, Visa, Sony, and more.

    Christophe Wille's AspTear freeware requests output by showing the SSI and distributed EDI in a connected way. Its latest version, AspTear 1.50, is documented as having the following features: retrieval of documents as strings, immediate saving to disk, extensive SSL support , proxy server support and page caching.

    This example shows the basic functionality of authentication and handling post requests in AspTear. It's written by the manufacturer. Source code for asptearinclude.asp can be found at http://www.alphasierrapapa.com/ComponentCenter/AspTear/help/examples-basic.html

    Listing 1.2

    
    <!-- #include file="asptearinclude.asp" -->
    <html>
    <head>
      	<META NAME="generator" CONTENT="Allaire HomeSite 4.0">
      	<title>Retrieval of POST page</title>
    </head>
    <body>
    <%
    Dim xObj, strResult, strUrl
    
    ' create the object
    Set xobj = CreateObject("SOFTWING.AspTear")
            
    On Error Resume Next
    
    ' set a referrer, don't cache pages, supply a custom user agent and a timeout
    xObj.Referrer = "http://www.vatican.va/"
    xObj.ForceReload = True
    xObj.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.0b2; Windows NT)"
    xObj.ConnectionTimeout = 45
    
    strUrl = Request.ServerVariables("SCRIPT_NAME")
    strUrl = Left(strUrl,InStrRev(strUrl,"/")) & "formpost.asp"
    strUrl = "http://" & Request.ServerVariables("SERVER_NAME") & strUrl
    
    ' URL, action, payload, filename, username, password
    strResult = xobj.Retrieve(strUrl, Request_POST, "test=it", "", "")
    HandleError
    
    Response.Write "<font color=""red"">" & strResult & "</font>"
    Response.Write "<br><b>Headers:</b><br><PRE>" & xObj.Headers & "</PRE>"
    %>
    
    </body>
    </html>
    
    
    Some of the lesser-known components include Flick's Software's OCXHttp. It's a Microsoft Foundation Class (MFC)-written COM component with InstallShield Software Corp.'s InstallShield install software to avoid the registration hassle. With full support for GET, HEAD, and POST requests, it can be used to set Accept Headers, UserAgent, Content-Type, Accept Ranges, Status Text, and cookies, including multiple cookies on one file. Flick's mentions it uses the Inet control, which others have avoided because of the documented problems with WinInet.dll. I don't understand why.

    Instantiating and using OCXHttp is similar and is also simple, but since this article focuses on the evolution of distributed EDI, I think it justifies writing some about this too.

    OCXHttp, like all other components, supported HTTP's standard GET, POST and HEAD requests for request-response. It also provides handy library functions like combineURL() to join a relative URL with a base-to-form absolute URL. With better optimization support, OCXHTTP has flags that can be set to avoid caching, forcing reloads and making existing session sharing possible. One can set response headers like the USER-Agent (browser) and server timeout as well. Another package, DynuHttp 1.0, is a free component. It can also retrieve documents using HTTP GET and POST, HTTP response headers, and has proxy support and authentication. For FTP they have provided a separate component named Dynuftp.

    The MS XML Revolution

    For information about the MS eXtensible Markup Language (XML) revolution, see http://msdn.microsoft.com/xml. Microsoft XMLHTTP, released as part of Internet Explorer 5.0 (and later) or IIS 5 (and later), created much change in the development vision. As a default-configured HTTP component, it was named "superglue for web" among the developer community. This suite was originally for the XML document object model (DOM) manipulation, but it included the XMLHTTP object for URI stream handling from local machine to World Wide Web. This object was developed extensibly enough to send GET/POST/Head requests and retrieve the XML/HTML or binary data as result. It came as an MSXML 3.0 parser (see MDAC at www.microsoft.com/data or http://msdn.microsoft.com/xml/general/xmlparser.asp).

    Microsoft ServerXMLHTTP was a replacement for XMLHTTP. It was claimed to make busy Web servers more reliable than its precursor could.

    Below I demonstrate how XMLHTTP can be used to implement the HTTP GET method, in this case Google. The mega search engine, Google, if provided with a search phrase in a query string, returns the search results. For example, it would return http://www.google.com/search?q=web+services where "web services" is the search phrase. This example is for educational purposes only. For commercial usage, one must read the terms and conditions for affiliate programs.

    Listing 1.3a
    xmlhttpexample.aspx

    
    
    <%@ Page aspcompat=true %> 
    <%
      Dim objXMLHTTP, xml
      ' Create an xmlhttp object:
       xml = Server.CreateObject("Microsoft.XMLHTTP")
    
      ' Version 3.0 of XMLHTTP, use:
      ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    
      ' Opens the connection to the remote server.
      xml.Open ("GET", "http://www.google.com/search?q=web+services", False)	
      ' Actually Sends the request and returns the data:
      xml.Send
      'Display the HTML and Text
      'Response.Write ("<h1>The HTML text</h1><xmp>")
      'Response.Write (xml.responseText)
      'Response.Write ("</xmp>")
    Response.Write ("<h1>This is generated results from google using XMLHTTP </h1>")
    Response.Write (xml.responseText)
     xml = Nothing
    %>
    
    

    Figure 1.2 Shows XMLHTTP's GET Request results.

    For ServerXMLHTTP, I have an interesting example. BAA Plc, the world's leading airport company, provides the live flight information for airports in the United Kingdom. If provided a flight number in a query string, it displays the flight status: Scheduled time, Coming from, Flight Number, Status and Terminal. In our case it's BA719 from Zurich. The query string seems long, but when I executed it without the airport number, the error result was

    DTWA000E: Net.Data detected an internal error DTWL018E: Net.Data detected a null value in parameter airport in function DTW_UPPERCASE.

    The above error message exposes the system libraries. URL parsing needs to be handled in a sophisticated way for all use-cases.

    Anyway, the query string with a flight number is written below, and the example shows how to retrieve flight information

    http://shop.baa.co.uk/cgi-bin/ncommerce3/ExecMacro/flights/arrivals.d2w/report? flightnumber=BA719&comingfrom=&hour=Hour&min= Min&hourselect=0&minselect=0&airport=LHR&timeframe= &terminalselect=0&terminal=All

    Listing 1.3b
    serverxmlhttpexample.aspx

    
    <%@ Page aspcompat=true %> 
    <%  Dim objXMLHTTP, xml, flightnumber, url
      '//Reading flight number from query string
       flightnumber=request("flightnumber")
    
      ' Create an Server xmlhttp object:
       xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
     url = "http://shop.baa.co.uk/cgi-bin/ncommerce3/ExecMacro/flights/arrivals.d2w/report?
    flightnumber="&cstr(flightnumber)
    &"&comingfrom=&hour=Hour&min=
    Min&hourselect=0&minselect=0&airport=LHR&timeframe=&terminalselect=0&terminal=All"  
      ' Opens the connection to the remote server.
      xml.Open ("GET", url, False)
    
     ' Actually Sends the request and returns the data:
      xml.Send
      Response.Write ("<h1>This is generated results from BAA using Server XMLHTTP </h1>")  
    Response.Write (xml.responseText)
     xml = Nothing
    %>
    
    

    Figure 1.3 Depicts BAA's GET Request results for flight information.

    Handling POST Requests Using ServerXMLHTTP

    Like GET, when using ServerXMLHTTP, it's also quite simple to do POST requests to remote Web sites. I demonstrate below how to query www.imdb.com (the Internet Movie Database) for the movie "My Big Fat Greek Wedding," one of the hilarious comedies of this year.

    Listing 1.4
    serverxmlhttppostexample.aspx

    
    <%@ Page aspcompat=true Debug="true"%> 
    <%
      Dim objXMLHTTP, xml, flightnumber, url
      ' Create an Server xmlhttp object:
       xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
       url = cstr("http://www.imdb.com/Find")
       xml.Open ("POST", url , False)
       xml.Send ("select=All&for=My Big Fat Greek Wedding")
      Response.Write ("<h1>This generated results from IMDB using ServerXMLHTTP </h1>")
      Response.Write (xml.responseText)
     xml = Nothing
    %>
    
    

    Figure 1.4 POST results from the Internet Movie Database.

    This is almost the same as GET, just the Open method argument was replaced with POST and the Send method now includes POST data.

    Syntax for data via post is the same query string, but the question mark ("?") used as a mark for the Web server to start processing the URL string is now eliminated.

    Forcing Downloads and Binary Data Transfer

    By setting up Content-Type, one can direct the binary responses to force downloads, transferring the responseBody variable to the Web browser. The example below demonstrates this using ServerXMLHTTP.

    Listing 1.5
    serverxmlhttpbinary.aspx

    
    <%@ Page aspcompat=true Debug="true"%> 
    <%  Dim xmlobject
      xmlobject = Server.CreateObject("MSXML2.ServerXMLHTTP")
      xmlobject.Open ("GET",  "http://www.jlctools.com/jlcsplitit/spltit32.zip", False) 
      xmlobject.Send() 
      ' Adding header
      Response.AddHeader ("Content-Disposition", "attachment; filename=spltit32.zip")	
      'Setting content type for webclient
      Response.ContentType = "application/zip"	
      ' Writing binary data
      Response.BinaryWrite (xmlobject.responseBody)
    %>
    
    

    Figure 1.5 Demonstrates binary file transfer and forcing downloads.

    Accessing HTTPS and Authentication via ServerXMLHTTP

    ServerXMLHTTP supports authentication. The Open method provides two optional arguments -- username and password. This is for the sites that ask for authentication credentials and set them by setting the WWW-Authenticate header. It can be either NT Challenge Response or otherwise. ServerXMLHTTP has username and password fields for this.

    Listing 1.6
    serverxmlhttpssl.aspx

    
    <%@ Page aspcompat=true Debug="true"%> 
    <%
      Dim xmlobject
      xmlobject = Server.CreateObject("MSXML2.ServerXMLHTTP")
      xmlobject.Open ("GET",  "https://www.verisign.com", False)
      xmlobject.Send()
      Response.Write (xmlobject.responsetext)
    %>
    
    

    Figure 1.6 VeriSign's HTTPS access. On the left, it's absolute access by pointing the browser to the secure site, while on the right is the screenshot of Listing 1.6. No images are displayed on the right because relative paths are not handled in the example.

    This is a sample of Verisign's secure site (https://www.verisign.com); HTTPS is secure HTTP. Images are not displayed because they are not addressed absolute.

    Enhanced Tunneling

    Web Services are an extension of what you experienced above. It's a simple concept. It can be stated as an application that is defined and published to be invoked over a network, for instance the World Wide Web via a protocol like HTTP. It's a distributed processing enhancement that provides standard description language, location, and execution mechanism with request-response standards.

    In contrast with previous mechanisms like Common Object Request Broker Architecture (CORBA), Remote Method Invocation (RMI), and Distributed Component Object Model (DCOM), Web Services are emerging as a widely accepted industry standard and a quantum leap in B2B e-business. It takes away many remote-procedural call and marshalling headaches, and gives a neat mechanism for distributed processing. Variable stub-skeleton formation (buffering a.k.a. marshalling) is a significant performance threat and is evacuated by HTTP-RPC.

    Two key terms when implementing Web Services are the Web Service Description Language (WSDL) and SOAP. I'll explain them later, but I found the definitions from World Wide Web consortium are more interesting. It will remind you of what we have discussed earlier about HTTP GET/POST. The consortium says the following:

    "WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services). WSDL is extensible to allow description of endpoints and their messages regardless of what message formats or network protocols are used to communicate, however, the only bindings described in this document describe how to use WSDL in conjunction with SOAP 1.1, HTTP GET/POST, and MIME."

    And for Simple Object Access Protocol (SOAP), the W3C's definition abstract is as follows:

    "SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML-based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses."

    This article focuses on the practical implementation of Web Services, but for those who need details, there's IBM's Web Services architect overview (see http://www-106.ibm.com/developerworks/webservices/library/w-ovr/?dwzone=webservices).

    XMethods, as its name suggest (see www.xmethods.com), is a library for methods implemented via Web Services. Its site calls itself a "virtual laboratory for developers, listing publicly available web services and showcasing new ways this technology can be applied."

    Laughter is the best medicine, and I found an interesting Web Service for jokes by Interpressfact (see http://interpressfact.net/webservices/)that accepts a SOAP envelope with a joke category ID in it and returns a random joke.

    This Web Service is listed on XMethods at the following URL: http://www.xmethods.com/ve2/ViewListing.po;jsessionid=o-uPkOFC7k2WkbBnr8b3ANUc(QhxieSRM)?serviceid=149694

    The WSDL for this service is located at http://www.interpressfact.net/webservices/getJoke.asmx?wsdl

    Now down to the business -- how to implement this Web Service using traditional XMLHTTP. As explained earlier, 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 is comprised of the getJoke namespace,

    
    <getJoke xmlns=""http://interpressfact.net/webservices/"">" 
    
    
    the required parameter category in DOM,
    
    <Category>category </Category>
    
    
    and lastly, setting the headers for method invocation.

    • Setting request as SOAP request for POST
    • Assigning HOST for SoapServer
    • Setting Content-Type as text/XML
    • encoding as UTF-8
    • Setting the SOAPAction for 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

    The XMLDOM function, xml.selectSingleNode, returns the joke as the end result. The complete listing explaining invocation is below. This is by interpressfact, but I made modifications to invoke categories by query string.

    Listing 1.7
    getJoke.asp

    
    <%' [ 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%>
    
    

    Figure 1.7 Shows the Interpressfact getJoke Web Service in action.

    You can invoke virtually any SOAP-based Web Service via this mechanism, although parameters needs to be changed.

    Implementation in .NET System.Net.WebClient

    No one doubts .NET has revolutionized the way ASP programming is done. Keeping backward compatibility in mind, .NET framework has provided an enhanced set of libraries to deal with programming problems and develop solutions. Especially by using .NET I/O and networking libraries, what was considered difficult before, can be made simpler and intuitive. I'm demonstrating a simple example of this below, after a brief introduction of the System.Net.WebClient class. As described in GNU (see reference section), the Common Language Interface (CLI) supports URIs with the "http:", "https:", and "file:" schemes. The WebClient class provides the following methods for uploading data to a resource:

    • System.Net.WebClient.OpenWrite(System.String) sends a stream to the server hosting a resource.
    • System.Net.WebClient.UploadData(System.String,System.Byte[]) sends a byte array to the server hosting a resource and returns a byte array containing the response from the server, if any.
    • System.Net.WebClient.UploadFile(System.String,System.String) sends a local file to the server hosting a resource and returns a byte array containing the response from the server, if any.
    • System.Net.WebClient.UploadValues(System.String,System.Collections.Specialized.NameValueCollection) sends a NameValueCollection collection to the server hosting a resource and returns a byte array containing the response from the server, if any.

    The WebClient class also provides the following methods for downloading data from a resource.

    • System.Net.WebClient.DownloadData(System.String) downloads data from a resource and returns a byte array.
    • System.Net.WebClient.DownloadFile(System.String,System.String) downloads data from a resource to a local file.
    • System.Net.WebClient.OpenRead(System.String) returns the data from the resource as a stream.

    In the example in Listing 1.8, the most commonly used function of the WebClient class, DownloadData, is used to demonstrate how easy it is to do what was once very difficult by using a third-party component.

    Listing1.8
    webClient.aspx

    
    <%
    dim refinedstuff, pos1, pos2
    dim webC As New System.Net.WebClient() 
    dim stuff as Byte()
    
    '//this function returns a byte array
    stuff= webC.DownloadData("http://www.census.gov/cgi-bin/ipc/popclockw")
    refinedstuff = Encoding.ASCII.GetString(stuff)
    pos1 = instr(refinedstuff, "<H1>") : pos2 = instr(refinedstuff, "</H1>")
    Response.write ("As per statistics from www.census.gov/cgi-bin/ipc/popclockw, <br>" )
    Response.write ("the world population is estimated to be " & mid (refinedstuff,pos1+4, pos2-pos1-4))s
    %>
    
    

    Figure 1.8 Demonstrates www.census.gov and its world population statistics.

    File Uploading in ASP.NET from a Remote Server

    How MIME types evolved could be the topic of a separate article, as could the difficulty of file uploading in the ASP-made emergence of commercial components. But to make a long story short, ASP.NET has made this task easier than ever before. What I found most interesting is I/O in Graphic Context System libraries, for example, similar-function-handling writing streams for both a hard-disk drive (HDD) and a browser. One can write on optical media or magnetic media in a similar way as it can be streamed to a Web client (browser), which shows the power of .NET classes. Listing 1.9 demonstrates this.

    Listing1.9
    webClientupload.aspx

    
    <%  
    ' instantiation of WebClient
     dim webObj AS New System.Net.WebClient()    
    '// Declaring and Setting URL Variable
     dim strURL 
     strURL ="http://msdn.microsoft.com/library/shared/toolbar/graphics/banners/MSDN_banner.gif"   
    '// Instance of Drawing Bitmap object based on strURL
     dim graphicContext = New System.Drawing.Bitmap(webObj.OpenRead(strURL ))  
    '//Setting Response types for web client
     response.contenttype="image/gif"  
    '// Saving it on HDD
     graphicContext.save("C:\\Documents\\logo2.gif", graphicContext.rawformat)  
    '// Writing it on web client 
     graphicContext.save(response.outputstream, graphicContext.rawformat)  
    ' Collecing the garbage & dereferencing
     graphicContext.dispose()  
     webObj = nothing  
     %>
      
    

    Figure 1.9 shows a similar file streamed to a web browser and hard drive.

    Web Services In .NET Perspective -- The Technology of Today

    Earlier I explained how interpressfact's getJoke Web Service works within a SOAP envelope using legacy ServerXMLHTTP. Lets experience the Web Service development and usage in .NET Framework.

    http://www.xmethods.com/ve2/ViewListing.po;jsessionid=o-uPkOFC7k2WkbBnr8b3ANUc(QhxieSRM)?serviceid=149694

    In the MS SDK for .NET, there is a tool called the "Web Services Description Language tool" or WSDL.exe. This command-line executable is used to create proxy classes from WSDL. For instance WSDL is located at http://www.interpressfact.net/webservices/getJoke.asmx?wsdl

    To create a proxy class called getJoke.cs, after the name of the class, as defined in Web Service definition source, do the following:


    Figure 2.1 This is the console-executing WSDL tool.

    This proxy class is later used in Web Service invocation.

    Conclusion

    In the next installment of this article, I'll discuss the implementation of this Web Service in .NET using SOAP with WebClient classes and demonstrate the power of .NET System.IO libraries. Also Google's pronounced API will be considered as a case study for a Remote Procedure Call (RPC) over HTTP using WebClient in .NET.

    About the Author

    Adnan Masood is a software engineer for UKIM in London and a consultant for www.hvwebmasters.com, the Hudson Valley Webmasters in New York. With a broad hybrid development vision on multiple software development technologies, Adnan's main expertise is in server-side programming, both Microsoft and open source.

    Being an active ASP and Java developer for the past five years, he's a computer science graduate holding a Bachelors of Science degree in Computer Science and a Sun Java-II Certification (SCJP-II). He can be reached via email at adnano@hvwebmasters.com.

    Reference Information

    Xmethods
    www.xmethods.com

    Karl Moss' Java Servlets
    http://books.internet.com/books/0071351884

    Christophe Wille's freeware AspTear
    http://www.alphasierrapapa.com/IisDev/Components/AspTear/

    Weberie Internet Service's AspHTTP
    http://www.weberie.com/components/asphttp/

    Dynu System Inc.'s DynuHTTP ASP Component
    http://www.dynu.com/dynuhttp.asp

    Flick Software's OCXHTTP
    http://www.flicks.com/OCXHttp/

    Google directory for web services
    http://directory.google.com/Top/Computers/Programming/Internet/Web_Services/

    http://www.w3.org/TR/wsdl
    http://www.w3.org/TR/SOAP/
    http://www.4guysfromrolla.com/webtech/040600-1.shtml

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q186842

    Unpatched IE Holes
    http://www.pivx.com/larholm/unpatched

    XML HTTP
    http://www.4guysfromrolla.com/webtech/110100-1.shtml

    http://www.tconsult.com/faq/shipping.aspx

    http://www.scriptlocker.com/goto/script.asp?scriptid=1157

    http://www.insightgraphics.com/reference/ITCRetrieval.htm
    http://aspfree.com/authors/Rakim_Ahmad/soap.aspx
    http://www.aspalliance.com/chrisg/default.asp?article=124
    http://www.xml.com/lpt/a/2002/04/24/google.html
    http://www.gnu.org/projects/dotgnu/pnetlib-doc/System/IO/Stream.html
    http://aspfree.com/authors/Rakim_Ahmad/soap.aspx
    http://interpressfact.net/webservices/
    http://www.xmethods.com/ve2/ViewListing.po;jsessionid=o-uPkOFC7k2WkbBnr8b3ANUc(QhxieSRM)?serviceid=149694
    http://www.interpressfact.net/webservices/getJoke.asmx?wsdl

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 7, 2005 - Hosting Indigo Web Services
    In the second article of his series on Indigo web services, Chris Peiris explains how to host an Indigo web service and examines the IIS, self hosting, and Windows Activation Service hosting options. He then provides step-by-step instructions and sample code for an IIS-hosted and self-hosted Indigo web service.
    [Read This Article]  [Top]
    Jun 8, 2005 - Indigo Programming Model
    In the first part of his series on Microsoft Indigo, Chris Peiris examines the basics of SOA, explains how Indigo fits into the picture and the problems it solves. He then introduces Indigo's programming model and finishes by building a sample Indigo web service using the Microsoft .Net Framework 2.0.
    [Read This Article]  [Top]
    Nov 10, 2004 - Business Intelligence with Microsoft SQL Server Reporting Services - Part 3
    Adnan Masood concludes his discussion of Microsoft SQL Server Analysis services and Microsoft SQL Server Reporting services. In the final part, he discusses Reporting Server web services and using custom code in reports.
    [Read This Article]  [Top]
    Jul 8, 2004 - Using IE's Web Service Behavior To Create Rich ASP.NET Applications
    This article explains the features of the IE Web service behavior and shows how to asynchronously communicate with an ASP.NET Web service directly from the client.
    [Read This Article]  [Top]
    Jul 6, 2004 - Using .NET and Excel 2003 To Validate E-Mails
    Calvin Luttrell shows how to validate e-mail addresses stored in Excel 2003 and provides a special function for solving that pesky problem Yahoo! mail servers cause.
    [Read This Article]  [Top]
    Jun 9, 2004 - Modifying Web Services Documentation
    This short article describes a quick and easy way to provide some security to an ASP.NET Web service by modifying its associated documentation file.
    [Read This Article]  [Top]
    Jun 2, 2004 - Kerberos Authentication with Web Services Enhancements 2.0
    Kerberos authentication is the cornerstone of Windows operating system authentication architecture. Web Services Enhancement 2.0 (WSE 2.0) extends Kerberos support to ASP.NET Web services. Chris Peiris explains the support for this new feature in WSE 2.0.
    [Read This Article]  [Top]
    Dec 15, 2003 - Realizing a Service-Oriented Architecture with .NET
    Chip Irek examines the architectural issues and component design issues of building a .NET application in a service-oriented architecture.
    [Read This Article]  [Top]
    Nov 24, 2003 - Consuming Asynchronous Web Services
    Thiru Thangarathinam shows how to use asynchronous Web services, Windows Service applications, server-based timer components and .NET XML API classes to create high-performance, scalable, and flexible applications.
    [Read This Article]  [Top]
    Nov 12, 2003 - Implementing Paging and XSLT Extensions Using XSLT in .NET - Part 2
    Part one showed how to transform XML data into HTML by using an XSL stylesheet from within a .NET application. This part explains how to make use of XSLT Extension objects and invoke a C# class method from an XSL stylesheet.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers