Discover ISAPI -- Feed Provider for Graphical Applets



Click here for a larger image.

Environment: ISAPI

Introduction

Some time ago, I implemented a data feed system from a SQL database to some graphical applets. At the beginning, we decided that a normal ASP script that read data and gave it to that applets would be useful. Unfortunately, it wasn't! The Web server crashed every time the number of simultaneous users on the site was bigger that 80-100 and when a user tried to get bigger data in an applet. For that reason, we decided to move the feed to the ISAPI DLL.

Advantages

  • The ASP server is freed by the calls from clients' applets. In that way, the ASP will respond only to the normal site calls; the ASP won't produce any time outs caused by applets calls.
  • Keeping the connection to the DB in the ISAPI cache. In that way, all requests against the DB won't lose time with the open connection; they will use that public open connection variable (CAdoDatabase m_AdoDB).
  • ISAPI extension DLLs are the best choice if you want to obtain the maximum number of simultaneous connections to the IIS Web server or to provide huge quantities of HTML data.

Functionality

The ASP script loads the applet class and gives it some parameters, such as colors, time interval of HTTP's requests, Web application URL, and so forth.

<applet codebase="../AspDemoFeed/Tools/OnlineScroll/CLASSES/
        JavaScroller/" archive="../AspDemoFeed/Tools/OnlineScroll/
        Scroller.jar" code="ScrollerStartUp.class" width="600"
height="20" VIEWASTEXT id="Scroller">
  param name="speed" value="3"
  param name="bgcolor" value="696969"
  param name="Font" value="Arial|1|16"
  param name="changeFontSize" value="11"
  param name= "feedURL"value="<%=Application("WebURL")%>cgi-bin/
              IsapiDemoFeed.dll?GetOnlineScrollerData?"
  param name="updateInterval" value="20000"</applet>

The Java applet will make HTTP requests from the client side to the Web server at the received Web URL parameter. That request is made an equal interval of times given in milliseconds by the "updateInterval" parameter. If you open the Java console on the client, you will see some messages such as:

Loading data from
http://localhost/projects/Articles/AspDemoFeed/cgi-bin/
       IsapiDemoFeed.dll?GetOnlineScrollerData?0&4

The ISAPI module responds to that HTTP hit with a known applet format, HTML stream:

0|2232160|453.4|2|14:19:06
1|576920|139.1|1|14:19:06
2|4006410|796.8|4|14:19:06
3|2511860|-31.5|2|14:19:06
4|2478810|529.2|0|14:19:06 

At each HTTP hit, the ISAPI module makes another request to the SQL database, using the CAdoDatabase and CAdoRecordset classes. The minor modification was to keep only the database connection as a public variable. On each method, the needed record sets are opened and closed. An optimization is the using of the GetString method of the AdoRecordset class, which returns directly formatted data text. Because the ISAPI DLL is harder to debug, more attention must be given to the errors capture, resolved with try/catch macros.

try
{CAdoRecordset* AdoRS = new CAdoRecordset;
               //create a recordset variable
  if ( DBConnectionOpen( m_bstrConnectionString ) )
               //look at the DB connection to see whether
               //it's online
  {            //open the recordset
    if ( AdoRS->Open(m_AdoDB.GetActiveConnection(), bstrSTMT,
         adOpenForwardOnly, adLockReadOnly, adUseClient ) )
               //here are the disc params
    { if(!AdoRS->IsEof())           //see whether we have records
        varOutput = AdoRS->GetString("|", "\n", 0 );
      else
        varOutput = "0 0 0 0 0 ";
      AdoRS->Close();              //close the recordset
      if (AdoRS) delete AdoRS;
    }else                          //set the custom error
    { wsprintf(wcOut,"Encountered Error:
      <br>%s<br>%s<br>%s<br>%s<br>","MyFunction"
      (LPCTSTR)m_AdoDB.GetLastError(), "RS isnt open", bstrSTMT );
      *pCtxt << wcOut ;            return;
    }
  }else                            //set the custom error
  { wsprintf(wcOut, "Encountered Error:
    <br>%s<br>%s<br>%s<br>%s<br>","GetMarketMapData",
    (LPCTSTR)m_AdoDB.GetLastError(), "DB isn't open", bstrSTMT );
    *pCtxt << wcOut ;              return;
  }
}
catch(_com_error err)
{   wsprintf(wcOut, "Encountered Error :
    <br>%s<br>%d<br>%s<br>", (LPSTR)err.Description(),
  err.Error(), (LPSTR)err.ErrorMessage() );
  *pCtxt << wcOut ;               return;
}
*pCtxt << varOutput;              //here's the output

Note: To test the feed, you must use make updates on the values of the tblOnline* tables. That updating will be online, reflected instantaneously to the online tables and scrolling applets. To see how Intraday charts applets are working, make inserts in tblIntraday* tables. Those applets look permanently at those tables and updates our values in cells and points to the charts.

Installing

  • The ASP connection string is located in the Includes\_incConnectionOn.asp file.
  •   cnx.Provider = "sqloledb"
      cnx.Open "Data Source=andi;Initial
                Catalog=ArticlesIsapiFeed;
          ", "sa", ""
    
  • The ISAPI connection string is located in the IsapiDemoFeed.cpp file, on the constructor:
  •   m_bstrConnectionString="Provider=SQLOLEDB;Data
                              Source=andi;
                              Initial
                              Catalog=ArticlesIsapiFeed;
    
      UserID=sa;Password=;";
    
  • Copy the folder "AspDemoFeed" under your Web site and make it an ASP application to work the session and application ASP objects.
  • Give the "Scripts and Executables" Execute Permission to the "cgi-bin" directory of the "AspDemoFeed" Web application. In that way, the ISS Web server will be able to execute the IsapiDemoFeed.dll.
  • To install the database on your SQL server, select the Restore Database option on SQL Server Enterprise Manager and choose the "DB/ArticlesIsapiFeed.bak" file backup. The name of the database is ArticlesIsapiFeed.

Downloads

Download ISAPI source files - 107 Kb
Download Web project files - 328 Kb
Download DB backup files - 319 Kb



Comments

  • It's very cool!!!

    Posted by Legacy on 12/20/2002 12:00am

    Originally posted by: fwsland

    It's very cool!!!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds