Developer .NET UPDATE—brought to you by the Windows & .NET Magazine Network
THIS ISSUE SPONSORED BY
Microsoft ASP.NET Connections
XML Web Services Connections
(below DEVELOPER .NET PERSPECTIVES)
SPONSOR: MICROSOFT ASP.NET CONNECTIONS
MICROSOFT ASP.NET CONNECTIONS TO CO-LOCATE WITH SQL SERVER MAGAZINE LIVE!
Microsoft ASP.NET Connections, along with VS.NET Connections will co-locate with SQL Server Magazine LIVE! in Orlando, FL, on Oct. 27 - 30. Full details for conference sessions, speakers, and workshops are now online. Over 170 sessions from top third-party gurus, Microsoft product developers, and magazine authors. This must-attend event will help you keep your skills sharp. Dig deeper into the Microsoft .NET Framework and discover how it will impact you and your company. Chock full of practical information you can use right away. Real-world technical tips and insights you don't want to miss. Register for one conference and attend the other two conferences for FREE. Go to
July 23, 2002—In this issue:
1. DEVELOPER .NET PERSPECTIVES
- WebMethod Attributes
- Don't Miss Our Storage Web Seminar—Free!
- Energize Your Enterprise at MEC 2002, October 8 through 11, Anaheim, CA
- Featured Thread: Transforming Old Code into a Visual Basic .NET DLL
4. NEW AND IMPROVED
- Debug PL/SQL Inside of Visual Studio .NET
5. CONTACT US
- See this section for a list of ways to contact us.
1. DEVELOPER .NET PERSPECTIVES
(contributed by Marquis Howard, [email protected])
Numerous articles and books are being written about Web services. Without going into repeated detail about how Web services work, let's look at some attributes that you can set on the Web methods you expose. One attribute is particularly helpful because it lets you cache the data of a Web service response. This discussion assumes you have general knowledge about the Web service technology. If you're unfamiliar with Web services, see Bill Sheldon, "What Is a Web Service?" by going to http://www.winnetmag.com/email/index.cfm?action=archive&emailnewsletterid=33 and selecting May 21, 2002 from the drop-down list.
I once used the Microsoft .NET Framework to create a few Web services, but I never knew about the attributes you can set on the methods. I had used a straightforward approach: I created public methods that another application would call as many times as necessary, not thinking about the impact on the server's performance. However, if data is coming from a database, you need to minimize the number of database hits.
For Web developers, minimizing the number of SQL queries whenever possible should be second nature, especially if a query returns a large amount of data. For an ASP.NET application, Output Caching and Application Data Caching work beautifully for lessening the hits on the server by caching data that's frequently requested. Caching works great in ASP.NET Web pages, but what about Web services?
Caching in Web services is similar to caching in an ASP.NET Web page: You can use the same Output Caching and Application Data Caching mechanisms. You have at your disposal the Cache object by way of the System.Web.HttpContext class. In an ASP.NET Web page, you can call this object's Insert method with code such as
Cache.Insert("Key", object, dependencies, absoluteExpiration, slidingExpiration, CacheItemPriority.High, onRemoveCallback)
However, in Web services you can't call the Cache object directly. While researching how to implement caching, I came across two approaches. One approach is similar to the approach used for ASP.NET Web pages. You call the Cache object's Insert method, except you must call the Context class first, with code such as
Context.Cache.Insert("Key", object, dependencies, absoluteExpiration, slidingExpiration, CacheItemPriority.High, onRemoveCallback)
Another way you can implement caching for a Web service is by setting a WebMethod attribute called CacheDuration. According to the Microsoft Developer Network (MSDN), CacheDuration is the number of seconds the response should remain in the cache. The default is 0, which means the server doesn't cache the response. When you enable caching, the server holds responses in memory for the cache duration, so you must use caution if you expect responses to be large or if you expect requests to vary widely. To set the CacheDuration to 60 seconds, you use code such as
<WebMethod(CacheDuration := 60)>
Recently, I used the CacheDuration attribute. In this implementation, the Web service has a WebMethod that returns a data set. This particular method receives quite a few requests at certain times of the day, so generating a new data set every time isn't efficient. In addition, much processing takes place to produce the data set, and no input parameters affect the returned data. When the WebMethod is called, the response takes from 15 to 25 seconds to appear. The data is somewhat volatile and changes every minute. By setting the CacheDuration to 60 seconds, the response data is in sync with the source data, but when the WebMethod is called, the cached response takes only 1 to 2 seconds.
You can set two other WebMethod attributes: BufferResponse and MessageName. BufferResponse reflects how Microsoft IIS handles a request's return stream. Typically, IIS waits until an entire response is ready or the response buffer is full before sending the response to the client. However, you can have IIS start sending a response as soon as there's data to send by setting this parameter to false. If you have a large data stream, using this setting can provide slightly better performance. However, in most situations, using this setting isn't a good idea because it might hurt performance.
The MessageName attribute lets you create an alias for the method name that a Web service exposes. This capability is important because the Web Services Description Language (WSDL) doesn't support polymorphic naming. Thus, for example, if you have a class implementation in which the GetRecord method can be called internally with an integer or a string, you need to have a different method name for at least one of the WebMethods.
Being aware that Web services have some built-in flexibility as to how you can define them and how they can respond is important. You'll have more control, which is always welcome.
If, like me, you didn't know about the caching approaches and WebMethod attributes associated with Web services, check them out. For more information about the Insert method, go to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebcachingcacheclassinserttopic.asp. For more information about the CacheDuration, BufferResponse, and MessageName attributes, go to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskusingwebmethodattribute.asp.
SPONSOR: XML WEB SERVICES CONNECTIONS
XML WEB SERVICES CONNECTIONS TO CO-LOCATE WITH WINDOWS & .NET MAGAZINE LIVE!
XML Web Services Connections and Windows & .NET Magazine LIVE! will co-locate from Oct. 30 - Nov. 2 immediately following Microsoft ASP.NET Connections, Visual Studio.NET Connections, and SQL Server Magazine LIVE! Deep discounts available for those attending the entire week of conferences. Save even more by registering now to lock in your early bird discount. Full details for conference sessions, speakers, and workshops are now online. Go to
(brought to you by Windows & .NET Magazine and its partners)
While the cost of buying storage capacity continues to drop, the cost of managing storage and keeping it available continues to rise. Find out why this happens and how to address it by bringing your Windows storage under control. Register today for this important online seminar sponsored by VERITAS!
Don't miss the essential Microsoft infrastructure conference where you'll connect with a world of expert information, technical training sessions, best practices, and hands-on labs. Be among the first 1000 to register and receive a free MEC 2002 DVD valued at $695—plus save $300!
A forum participant needs help in transforming existing code into a Visual Basic .NET DLL. If you can help, go to the following URL:
4. NEW AND IMPROVED
(contributed by Carolyn Mader, [email protected])
Compuware announced DevPartnerDB Debugger for Oracle, Visual Studio Edition, a development tool for performing proactive analysis and debugging of Procedural Language/SQL (PL/SQL), an Oracle programming language, within the Visual Studio (VS) and Visual Studio .NET environments. The product shows you how applications interact with the database. You can find and fix data-access problems quickly before development. DevPartnerDB Debugger for Oracle, Visual Studio Edition, supports Windows XP, Windows 2000, and Oracle 8.0 and later. Pricing is $399.
5. CONTACT US
Here's how to reach us with your comments and questions:
- ABOUT DEVELOPER .NET PERSPECTIVES — [email protected]
- ABOUT THE NEWSLETTER IN GENERAL — [email protected]
(please mention the newsletter name in the subject line)
- TECHNICAL QUESTIONS — http://www.winnetmag.net/forums
- PRODUCT NEWS — [email protected]
- QUESTIONS ABOUT YOUR DEVELOPER .NET UPDATE SUBSCRIPTION?
Customer Support — [email protected]
- WANT TO SPONSOR DEVELOPER .NET UPDATE?
This weekly email newsletter is brought to you by Windows & .NET Magazine, the leading publication for Windows professionals who want to learn more and perform better. Subscribe today.
Receive the latest information about the Windows and .NET topics of your choice. Subscribe to our other FREE email newsletters.
Thank you for reading Developer .NET UPDATE.