How to Build a Low-Budget Web Service with Classic ASPBy Jason Salas
With the increasing interest in XML Web Services platforms from the various major vendors (i.e., Microsoft's .NET Framework, Sun's J2EE, IBM's WebSphere), many people have expressed an interest in getting their content to be shared by site owners and entities external to their organization. This ranges in function from the simple co-branding marketing service all the way up to an advanced e-commerce app that allows for the exchange of data between partners in a B2B relationship. And up until this point, accessing data from resources not within the same Web or network was extremely difficult to do, if not completely impossible.
Your Most Powerful Asset - Information (or Understanding Why Web Services Rule)
It's a very competitive advantage if you can offer your content to partners for use on their own sites, and it serves you very well. Large, dominating sites such as MSNBC.COM do this to stay ahead of the competition in the online news game by offering their headlines and story abstracts to other sites. The end result is that the content provider ultimately gets the traffic, which is a win for justifying traffic levels, which leads to revenue gains. And smaller sites love to incorporate remote content on their pages to stimulate traffic increases by way of association with larger entities. But the added overhead due to additional database connections is an unwanted headache for developers.
So, our "Web service" consists of a very simple script which works with the following:
.JSextension) are "portable" in the sense that they can be referenced from within the HTML source code of a remote client page, with their contents being displayed. Thus, we can write a very simple code construct to get content portable.
- Publishing the
- This service never relies on external clients directly connecting to your database, so there isn't an
additional overhead concern other than the made by you when running the script. This prevents your main
site from being bogged down. That's the beauty of it - you can control how many times the script is
invoked if you embedded the script in an administration page, which would be executed by a staffer in
your organization. So you could literally have tens, hundreds, or thousands of clients using your service
and the load would at be the same minimal level, because you're essentially only connecting to your
portablecontent.js) is as follows:
<!-- document.writeln('<a target="_blank" ' + 'href="http://www.yourdomainname.com/filename.asp?id=8675309">' + '<b>Senators debate during session sale of GTA</b>' + '</a><br>'); document.writeln('The privatization of the Guam Telephone Authority is being touted ' + 'as a top priority of the Gutierrez administration, as its sale is ' + 'expected to bring some major </a><br>'); .....more content as needed..... //-->
This has benefits for the client, in that:
match the flow and theme of their page(s).
- The script also truncates a "description" field and appends
...if the string is too long. This saves you from having to modify your table structure in an existing database.
file and then never touches it again. The remote site manager also has peace of mind about not sacrificing
traffic to their own if the user clicks away, because we'll open a new browser window by using the HTML
The only assumption is that you will have a file sitting on your server with the path (you can edit this to
match your own site's settings)
There is one concern you'll want to watch out for, however (I learned this the hard way), in that single
quotation marks "
turn will generate an error on the client's page, making for an ugly and dysfunctional service. And with much
database-driven content being generated by forms - transmitting data in ASCII - this could run into problems.
Fortunately, Unicode characters don't have this problem. As a workaround, I employ VBScript's Replace function
to check for the existence of ASCII-type single-quotes, swapping each one with a Unicode single-quote, which
character using NotePad, and the Unicode single-quote character using MS Word.)
Get the Word Out - Promoting your "Web Service"
You can then promote the heck out of your new "Web service" by having interested users insert the following HTML into their Web page(s):
Plan your Code, Code your Plan
The code needed to create this
.JS file is fairly simple and straightforward. All we need to
using the FileSystemObject object. To learn more about this object, be sure to check out the
FileSystemObject FAQs on ASPFAQs.com.
Next, a connection to the database is made, and the headlines and their information are loaded into a Recordset.
checking to see if the description is longer than 165 characters - if it is, only the first 165 characters (and
perhaps some more, up until the next word) are displayed, followed by a
That's essentially all there is to it! The code is not extremely long, but to lengthy to place in this article. Therefore, you can view the source code in a separate window. Feel free to modify this code however you see fit, such as just displaying headline information and forgoing the description. You can see an example of the output my script generates here; to the right is an image of the headlines as they might appear on a Web site utilizing this Web service I created.
.NET Web Services Allow for Greater Flexibility and Choice
The only limitation is that with a system such as this, the client has very little say in what he/she can do with the resultant data (e.g., filtering for content, subscription-driven services, etc.). The client can modify formatting for presentation purposes, but that's about it. MSNBC has a very powerful portable product that it makes available to its affiliate stations across the U.S. wherein site managers can pick-and-choose which newsfeeds they wish to receive as MSNBC updates its site.
This is the big draw of XML Web services with the .NET Framework - the service provider exposes access to the data to the client, and the client decides what to do with it to best fit his situation. But for now, this is just an example of one of the many things you can do to drive more traffic to your site by leveraging the single-most important asset you've got - information. To learn more about Web Services with ASP.NET, check out this Web Service Tutorial.
Jason Salas is Web Development Manager for KUAM.COM, one of Guam's most popular Web sites. He also writes business and technology-oriented columns for KUAM.COM, and hosts the weekly segment "Tech Talk" on KUAM-TV, a whimsical look at what's new on the technical front and the Internet subculture. He has worked in the information technology industry for more than 11 years as a salesperson, marketing manager, developer, consultant, and author. He also owns IntelliBiz, a consulting company focusing on developing XML Web services. He is a graduate of Simon Sanchez High School, has a Bachelor's degree in Marketing from the University of Guam, a degree in Music Theory with Emphasis in Guitar from the Sutton Institute in Texas, and a Master's degree in Management of Applied Technologies from the University of Phoenix. He is also a Microsoft Certified Professional.