Archives

Archives / 2007 / July
  • Video: First Look at Visual Studio .NET 2008 and the LinqDataSource

    Visual Studio .NET 2008 provides many new features that will definitely enhance developer productivity.  In this video tutorial I provide an introductory look at VS.NET 2008 and show a few features such as multi-targeting, split view, and the LinqDataSource control.  In the video you'll see how to build an ASP.NET page that retrieves data from a data context object (created with the new LINQ to SQL designer) and binds it to various controls using the LinqDataSource control.

      
    View the Video

     

     

    Read more...

  • VS.NET 2008 Beta 2 Now Available to Download

    If you haven't heard already, VS.NET 2008 beta 2 is now available for downloading.  I'm installing it right now. :-)

    http://www.microsoft.com/downloads/results.aspx?DisplayLang=en&nr=20&freetext=visual+studio+2008&sortCriteria=date

    Make you sure read Scott Guthrie's blog after the installation.  He links to a batch file that needs to be installed afterwards to fix some policy issues on the System.Web.Extensions.dll assembly.

    http://weblogs.asp.net/scottgu/archive/2007/07/26/vs-2008-and-net-3-5-beta-2-released.aspx

    Read more...

  • Using the ASP.NET AJAX ScriptMethodAttribute to Return XML Data

    Web Services provide a convenient way to pass data between AJAX applications and a server.  ASP.NET AJAX provides an excellent infrastructure for Web Service integration into AJAX applications and makes it all cross-browser through incorporating JSON into the mix.  While JSON is compact and a very good fit for AJAX applications, there may be times where it's easier or more convenient to pass back raw XML to an AJAX client for processing.  This is especially true if the browser provides robust XML parsing APIs like Internet Explorer 5+.  For example, you may have a Web Service that obtains RSS data and returns it as an XmlDocument or XmlElement object.

    Switching between JSON and XML response messages is accomplished by using the ASP.NET AJAX Extensions's ScriptMethodAttribute.  It can be used to specify the response type of a given Web Method and even control if the method accepts GET requests (POST is the default which is good given the existence of CSRF attacks). 

    An example of using the ScriptMethodAttribute class to return XML data from a Web Method is shown next.  You'll see that the ResponseFormat property is set to ResponseFormat.Xml instead of ResponseFormat.Json.  Keep in mind that this is really only useful if the browser supports XML parsing, which means it may be most applicable in Intranet scenarios where a standard browser such as IE is used throughout a company.

    [ScriptMethod(ResponseFormat ResponseFormat.Xml)]
    [WebMethod]
    public XmlElement GetRssFeed(string url)
    {
        XmlDocument doc 
    = new XmlDocument();
        
    doc.Load(url);
        return 
    doc.DocumentElement;
    }

    The following code demonstrates how to call the GetRssFeed() Web Method and parse the returned XML data using Internet Explorer's XML parsing APIs:

    <script type="text/javascript">
        
    function GetRss()
        {
            InterfaceTraining.DemoService.GetRssFeed(
    "http://blogs.interfacett.com/dan-wahlins-blog/rss.xml",OnWSRequestComplete);
        
    }

        
    function OnWSRequestComplete(result)
        {                
            
    if (document.all) //Basic way (very basic) to check for IE DOM
            
    {
                
    var items result.selectNodes("//item");
                for 
    (var i=0;i<items.length;i++)
                {
                    
    var title items[i].selectSingleNode("title").text;
                    var 
    href items[i].selectSingleNode("link").text;
                    
    $get("divOutput").innerHTML +
                       
    "<a href='" + href + "'>" + title + "</a><br />";
                
    }
            } 
    else
            
    {
                $
    get("divOutput").innerHTML "RSS not available in this browser.";
            
    }
        }
       
    </script>

    Read more...

  • Aborting AJAX Requests

    The ASP.NET AJAX script library provides a simple way to abort asynchronous postback requests in cases where users decide they don't need data they originally requested.  This can be done without tying into different PageRequestManager events.  Instead, the abortPostBack() method can be called as shown in the code that follows.  For more information on aborting AJAX requests you can read my latest .NET Insight article here.

    function btnAbort_Click()
    {
        
    var prm Sys.WebForms.PageRequestManager.getInstance();
        if 
    (prm.get_isInAsyncPostBack())
        {
            prm.abortPostBack()
    ;
            alert
    ("Postback aborted!");
        
    }
        
    else
        
    {
            
    alert("No postback operation is in progress.");
        
    }
    }

    Read more...

  • Updated: List of AJAX Automated Testing and Debugging Tools

    While there are a lot of testing tools out there to look for bugs, test a Website's scalability and perform unit tests, precious few seem to handle automating the testing of AJAX applications.  As a result, I wanted to start a list of tools that support automated testing of AJAX applications as well as debugging.  If you have other tools or applications you know of or something listed is out of date please add a comment to the blog and I'll get the information added/updated.

    • ASP.NET AJAX Enhancements Library - The ASP.NET Ajax Enhancements Library is designed to provide an automated Unit Testing framework that integrates with VS.NET.  It also includes a client-side library that adds additional features to the Microsoft supported ASP.NET 2.0 Ajax Extensions Core library that do not currently exist in the Futures CTP.  The client-side library adds some nice short-cuts (haven't tried them yet...but they look interesting) such as $foreach and $break, as well as List and Dictionary classes.  It also includes a LINQ to JavaScript implementation.  Cost: Free
    • Custom AJAX Testing - Article by James McCaffrey that discusses creating custom AJAX test automation scripts. Cost: Free
    • jsMock - JSMock is a fully featured Mock Object library for JavaScript that provides the necessary tools to do effective interactive based testing. JSMock provides expectation recording and matching, and has the ability to return, throw, and stub on object method calls. The interface is simple and easy to use, which makes testing easy. Cost: Free
    • jsUnit - JsUnit is a Unit Testing framework for client-side (in-browser) JavaScript. It is essentially a port of JUnit to JavaScript. Also included is a platform for automating the execution of tests on multiple browsers and mutiple machines running different OSs.  An article on using jsUnit can be found here.
    • InCisif.net - InCisif.net is an automation tool designed to implement client-side functional testing of web applications under Internet Explorer 6.x or 7.x, using the C#, VB.NET or IronPython language.  You can read an article about using the tool for AJAX testing here.
    • Selenium - A test tool for web applications. Selenium tests run directly in a browser, just as real users do. And they run in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh. Cost: Free
    • Sprajax - Although not a test automation tool, Sprajax allows AJAX applications to be scanned for potential security threats. Cost: Free
    • Squish - froglogic Squish is a professional cross platform automated GUI and Web testing framework.  Squish allows to create tests for GUI and Web applications by recording or manually writing test scripts. Squish supports popular scripting languages for the test scripts and gives access to additional APIs. This way QA engineers can easily create powerful and robust tests to enhance and keep up the quality of the tested application. Cost: Unknown
    • SWExplorerAutomation (SWEA) - This program creates an automation API for any Web application which uses HTML and DHTML and works with Microsoft Internet Explorer. The Web application becomes programmatically accessible from any .NET language. Cost: $99
    • WaitiN - WatiN is developed in C# and aims to bring you an easy way to automate tests with Internet Explorer. An article discussing WaitN can be found here.  Cost: Free
    • Web2test - Automated testing of web-based applications and portals, browser and platform independent, drag-and-drop, capture and replay.  Cost: 1.595,00 (euro price)
    • WebAii - Caters specifically to automated testing of the "Web 2.0" generation of internet applications. WebAii is one the most advanced and rich .NET automation infrastructures available in today's market and is provided FREE of charge to the developer and quality assurance community. WebAii just recently released their Beta 2 feature set. With Beta 2 you will be able to execute your javascript unit tests directly from managed code and from Visual Studio Team System... for both firefox and IE. Cost: Free
    • WindMill - Windmill is a web testing framework intended for complete automation of user interface testing, with strong test debugging capabilities.  Windmill is a web testing framework intended for complete automation of user interface testing, with strong test debugging capabilities. The first goal of Windmill to make test writing easier, portable and sustainable. The second goal of Windmill is to keep the project open and transparent, encouraging as much outside contribution as possible. Cost: Free

    Several AJAX debugging tools are listed below:

    • Aptana - The Aptana IDE is a free, open-source, cross-platform, JavaScript-focused development environment for building Ajax applications. It features code assist on JavaScript, HTML, and CSS languages, FTP/SFTP support and a JavaScript debugger to troubleshoot your code. Cost: Free
    • 1st JavaScript Editor Pro - 1st JavaScript Editor is used for professionally editing JavaScript code and creating animations and other special effects for Web pages using DOM, DHTML, CSS, Ajax (Asynchronous JavaScript and XML) and JavaScript. Cost: $49.90
    • FireBug - Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page. Cost: Free
    • Fiddler - Fiddler is a HTTP Debugging Proxy which logs all HTTP traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP Traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Cost: Free
    • JavaScript HTML Debugger - SplineTech JavaScript HTML Debugger is an award-winning JavaScript Debugger that enables you to easily edit and debug JavaScript and VBScript inside HTML pages. Client-Side JavaScript, JScript and VBScript debugging languages are fully supported for simple and complex HTML and DHTML debugging scenarios. Cost: $89.00
    • MyEclipse AJAX Tools - The MyEclipse AJAX / Web 2.0 toolkit features an enhanced JavaScript Editor and JavaScript Debugger (Professional Edition feature). Cost: $50 Annual subscription
    • Script Debugger - The Microsoft Script Debugger is a debugging environment that extends any Microsoft ActiveX® Scripting host application—for example, Microsoft Internet Explorer (IE) or Microsoft Internet Information Server (IIS). Cost: Free
    • Venkman - Venkman is the code name for Mozilla's JavaScript Debugger. Venkman aims to provide a powerful JavaScript debugging environment for Mozilla based browsers. Cost: Free
    • Visual Studio .NET (and Web Developer Express) - Development IDE that provides integrated JavaScript debugging capabilities. Cost: Free and pay versions
    • Web Developer Helper - Web Development Helper is an Internet Explorer plugin written by Microsoft's Nikhil Kothari that provides a set of useful tools to both Ajax/JavaScript developers as well as ASP.NET page and control developers. Cost: Free

    This is a growing list so check back often for new entries.

     

    Read more...

  • ASP.NET AJAX Health Care Toolkit Controls

    Patrick Long recently blogged about some new ASP.NET (and WinForms) controls released on CodePlex that are specific to the health care industry.  Several of the controls are AJAX-enabled (based upon the ASP.NET AJAX Extensions and the Toolkit) and as I went to download them I found an online demo available here.  I wish I would've had some of these controls on past health care projects I worked on.  An example of one of the more robust controls called MedicationGrid is shown below:

    Read more...

  • Windows Live Mobile Search V2 Released!

    The coolest program I have for my Windows Mobile phone (by far) is Windows Live Mobile Search V1.  I use it daily to check how traffic looks as I'm driving to downtown Phoenix.  V2 of the program has been released that adds the following new features (and I see there's even a beta for BlackBerry users...but iPhone users are out of luck):

  • Movie Showtimes:  Want to see a movie but don’t know what’s playing?   Get Movie Showtimes near you and be on your way! 
  • More Local Data with Reviews:  Want to go out for dinner but not sure which restaurant to pick?  Let your fellow restaurant goers help you out – make a decision based on user ratings.
  • Maps:  View Mobile Virtual Earth maps wherever you are.  For improved performance, pop in your storage card to enable the large cache option. Street maps, Aerial and Hybrid are supported.
  • Directions: Lost?  Get found with better support for GPS integration and improved turn-by-turn navigation.  We’ll even prompt you to auto-reroute if you get lost! 
  • Download the .cab file from http://mobile.search.live.com/client/download.aspx

    Read more...

  • Book: Beginning ASP.NET 2.0 AJAX Released

    Wally McClure, Steve Smith and several others recently had their Beginning ASP.NET 2.0 AJAX book released.  I hear that lines at book stores around the world were huge and people have been camping out for days to be the first ones to get it. :-)  Congrats to everyone involved with writing it.  I haven't seen it yet, but knowing several of the authors I'm sure it's excellent.

    If you're working with ASP.NET AJAX you may also want to check out the Professional ASP.NET 2.0 AJAX book that Matt Gibbs and I co-authored as well.


    Read more...

  • Exchanging Binary Data with MTOM and Web Services

    In the distributed computing class I'm teaching this week we're covering a few topics related to the Web Service Enhancements V3 (WSE3).  One of the nice features of WSE3 (and WCF for that matter) is that it can be used to exchange binary data quite easily and in an efficient manner by using MTOM.  I put together a demo project that shows how MTOM can be used to exchange binary data between a client and a Web Service.

    The demo code dynamically generates bar and line chart images using .NET and GDI+.  A client can pass XML data representing the data to chart to the Web Service and the service will handle dynamically generating the chart image and return it to the client using MTOM.  The code for the demo can be downloaded here.

    Read more...

  • Coping with Click-Happy AJAX Application Users

    Users can be impatient while waiting for data to be returned to a page (I'll admit I'm guilty of this occasionally).  Fortunately, ASP.NET AJAX makes it easy to handle cases where impatient users continually click a refresh button (or other type of button) in an ASP.NET AJAX page causing extra load to be placed on your server.

    Instead of allowing continuous requests to reach the server before their initial request has returned, you can easily let users know to kindly wait until their first request has returned and then cancel the subsequent request they've made.  This can be done by using the PageRequestManager to handle the initializeRequest event.  An example of performing this task is shown below.  More details can be found in my latest .NET Insight article.

    Sys.Application.add_init(Init);
    var 
    prm = null;

    function 
    Init(sender)
    {
       prm 
    Sys.WebForms.PageRequestManager.getInstance();
       if 
    (prm)
       {
          
    if (!prm.get_isInAsyncPostBack())
          {
              prm.add_initializeRequest(InitRequest)
    ;
          
    }
       }
    }

    function InitRequest(sender,args)
    {
        
    if (prm.get_isInAsyncPostBack() && 
          args.get_postBackElement().id 
    == 'btnRefresh') {
           args.set_cancel(
    true);
           if 
    ($get("divChill").style.visibility !"visible")
           {
              $
    get("divChill").style.visibility "visible";
              
    setTimeout("ClearDiv()"2000);
           
    }
        }
    }

    function ClearDiv()
    {
        $
    get("divChill").style.visibility "hidden";
    }

    Read more...

  • Tracing in ASP.NET Application Classes

    I'm a big fan of tracing in .NET and use it in every project I work on since it's a great way to find out why things aren't working properly.  Tracing is especially useful when an application works in a test environment but not in production.  My good buddy Michael Palermo recently wrote a nice post on how to dynamically grab the name of a method when using tracing which is a great idea.  Mike's post made me think about a question I'm often asked: "How do you perform tracing in classes that don't have direct access to the ASP.NET TraceContext object?".

    There are several potential answers to this question.  Some or good and some are bad.  You could pass a Page object instance to business object methods that need to write to the ASP.NET trace log but this would break some fundamental architecture principles so it's not something I'd recommend.  You could also perform a trace operation in a business or data layer class by using the HttpContext class as shown next (you could used Michael's suggested technique to dynamically add the target method name into the message text):

    HttpContext.Current.Trace.Warn("Category","Message text");

    While this works, using HttpContext ties the class where it's defined to the Web and makes it less useful in desktop or other non-Web applications (without checking to see if an HTTP context exists anyway).  I'll admit that I use the HttpContext technique for demos since it's quick and easy, but for more enterprise applications there's a better technique that you might want to consider.  

    The System.Diagnostics namespace provides a Trace class that can be used to route data to the ASP.NET trace log exposed by viewing Trace.axd in the browser.  You'll have to add some minor configuration code into web.config to get it to work, but it's quite simple.  Here's an example of using the System.Diagnostics.Trace class's Write() method:

    Trace.Write("Category","Message text");

    To enable trace messages created by classes used in an ASP.NET application to be written to the ASP.NET trace log, you can add the following code to web.config (add it outside of the system.web tag) which listens for trace operations and uses the System.Web.WebPageTraceListener class to write them to the trace log:

    <system.diagnostics>
        
    <trace>
            
    <listeners>
                
    <add name="WebPageTraceListener" 
                  type
    ="System.Web.WebPageTraceListener, System.Web, 
                            Version=2.0.3600.0, Culture=neutral, 
                            PublicKeyToken=b03f5f7f11d50a3a"/>
            </
    listeners>
        
    </trace>
    </system.diagnostics>

    The value supplied to the type attribute should be placed on a single line in web.config of course.

    By using the System.Diagnostics.Trace class (and related configuration code) with custom business or data classes you can use these classes with Web or desktop applications since the trace operations aren't tied to HttpContext any longer.  Desktop applications would simply need to change the listener class in app.config to have trace operations written to a log file or other location.  A class such as System.Diagnostics.TextWriterTraceListener could be used in this situation.

     

    Read more...

  • .NET 2.0 Distributed Application Programming Sample Code

    For those taking the Distributed Application Programming course this week with me (or anyone else who is interested), you can download some samples I put together below.  You'll find samples of creating and consuming Web Services, creating remoting clients and servers, using MSMQ and securing SOAP messages using WSE 3.0. 

    Although this class doesn't cover WCF, you'll also find a "getting started" video and a step-by-step tutorial below that both discuss how to create a WCF service and consume it using svcutil.exe.

    Read more...

  • Using the ASP.NET AJAX PageRequestManager to Provide Visual Feedback

    ASP.NET AJAX provides an UpdateProgress control that greatly simplifies the process of providing users with visual feedback as asynchronous postback operations occur in AJAX applications.  By using the control you can easily show an image, Flash movie, Silverlight animation, etc. while an AJAX asynchronous postback operation is in process.

    In situations where you want more control over the type of visual feedback that is provided to users, you can use the ASP.NET AJAX script library's PageRequestManager client-side class to access the page's life-cycle.  For example, if you want to animate a div tag that wraps an UpdatePanel control each time the UpdatePanel performs a partial-page update, you can hook into the beginRequest and endRequest client-side events to you know when a call is beginning and when it is ending. 

    The following script shows how these two events can be used to dynamically change the CSS class assigned to a div tag (that wraps an UpdatePanel) on a timed basis while the UpdatePanel control is updating its content.  In this example, an Animate() method is called which alternates the div's CSS class between one called DottedLines and one called SolidLine every 1/2 second.  This provides users with visual feedback so they can see when one or more UpdatePanel controls are updating.  While this is a fairly straightforward animation example, many more complex (and cool) techniques could be applied.  The ASP.NET AJAX Toolkit has some powerful animation capabilities built-in as well that you may want to take a look at.

    Sys.Application.add_init(Init);
    var 
    intervalID = null;

    function 
    Init(sender)
    {
      
    var prm Sys.WebForms.PageRequestManager.getInstance();
      
    if (prm)
      {
          
    if (!prm.get_isInAsyncPostBack())
          {
                prm.add_beginRequest(BeginRequest)
    ;
                
    prm.add_endRequest(EndRequest);
          
    }
      }
    }

    function BeginRequest(sender,args)
    {
        intervalID 
    = window.setInterval("Animate()"500);
    }

    function EndRequest(sender,args)
    {
        
    window.clearInterval(intervalID);
        
    $get("divAnimate").className "Normal";
        
    $get("lblLastUpdate").innerHTML = new Date().toLocaleTimeString();
    }

    function Animate()
    {
        
    var div $get("divAnimate");
        
    div.className GetCssClass(div.className);
    }

    function GetCssClass(currClass)
    {
        
    return (currClass=="DottedLines")?"SolidLine":"DottedLines";
    }

    if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded()

     

    Read more...

  • Understanding WS-This and WS-That Web Service Standards

    If you have to create or consume Web Services then you've likely come across the WS-* protocols that exist in varying forms.  Here's a few of them:

  • WS-Security
  • WS-Transfer
  • WS-Trust
  • WS-SecureConversation
  • WS-Policy
  • WS-Addressing
  • WS-Federation
  • WS-ReliableMessaging
  • WS-AtomicTransaction
  • WS-MetadataExchange
  • While you can always visit the OASIS or W3C Websites to learn more about these protocols, Michelle Lerouix Bustamante recently wrote an article on the topic titled Making Sense of all these Crazy Web Service Standards.  It's a good read that will get you up-to-speed quickly on what WS-This and WS-That actually mean. :-)

     

    Read more...

comments powered by Disqus