Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
 Thursday, June 19, 2008

Just in case you are studying WCF.. You might want to check out the .NET StockTrader Sample Application.

The .NET StockTrader Sample Application is an end-to-end sample application illustrating Windows Communication Foundation and .NET Enterprise Technologies. It is a service-oriented application based on Windows Communication Foundation (.NET 3.0) and ASP.NET, and illustrates many of the .NET enterprise development technologies for building highly scalable, rich "enterprise-connected" applications. It is designed as a benchmark kit to illustrate alternative technologies within .NET and their relative performance.

The application offers full interoperability with J2EE and IBM WebSphere's Trade 6.1 sample application. As such, the application offers an excellent opportunity for developers to learn about .NET and building interoperable, service-oriented applications.

Read more here: http://msdn.microsoft.com/en-us/netframework/bb499684.aspx

I've been diving into WCF lately and I have found this sample application as a great blueprint on how to develop applications using WCF & ASP.NET. The sample includes a smart client and an ASP.NET application that you can jump on and play that showcases as huge list of technologies and approaches when developing an SOA app via WCF and .NET

Below is a list of technologies that's demonstrated in this sample application:

  • Service-oriented, n-tier design with ASP.NET and WCF
    • Clean separation of UI, business services and DB access
    • Design and tuning for performance
    • Horizontally scalable via dynamic clustering
    • Centralized configuration management of clustered service nodes
  • .NET 3.5 with Windows Communication Foundation
    • Interoperability with J2EE/WebSphere Trade 6.1
    • Incorporates alternative designs for performance comparisons
    • Loosely-coupled, message-oriented design with WCF and MSMQ
    • Achieving assured message delivery with transactions
    • Self-hosting WCF Services
    • Custom WCF Behaviors
    • Service host failure detection and automatic restarts
  • .NET Enterprise Application Server Technologies
    • ASP.NET 2.0
    • ADO.NET 2.0
    • .NET Transactions
    • MSMQ 3.5 (Windows XP/Windows Server 2003)
    • MSMQ 4.0 (Windows Vista/"Longhorn Server CTP")
    • Transaction batching with WCF and MSMQ

Try and see for yourself ;) I bet you will enjoy it too!

 

Thursday, June 19, 2008 10:08:05 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | ASP.NET
 Thursday, April 17, 2008

In my previous article I showed you how to add a web service reference in your ASP.NET application, call a webmethod and the display the values returned byt the web service to a Label. This time I'm going to show you how to transform that Xml string into a DataSet.

I suggest that you read the previous article before continuing in reading this post so you'll have a better insight on what we are trying to accomplish on this article.

Let's begin!

To start off this article let's look at how the application that we built for the previous article.

and the HTML code for the UI

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Keith Rull's Consuming Web Services Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <strong>Symbol</strong><br />
            <asp:TextBox ID="symbolTextBox" 
                         runat="server" />
            <asp:Button ID="executeButton" 
                        runat="server" 
                        Text="Execute"
                        OnClick="executeButton_Click" />
            <br />
            <br />
            <strong>Result</strong>
            <br />
            <asp:Label ID="xmlResultLabel" 
                        runat="server" />
        </div>
    </form>
</body>
</html>

and the underlying code for the click event of the "Execute" button

    protected void executeButton_Click(object sender, EventArgs e)
    {
        //get the execution symbol entered in the TextBox
        string executionSymbol = symbolTextBox.Text;

        //get the stock quote information
        string quoteInfo = GetStockQuoteInformation(executionSymbol);

        //HtmlEncode the string to properly render it on the page
        string htmlEncodedResult = System.Web.HttpUtility.HtmlEncode(quoteInfo);
       
        //assign the HtmlEncoded string to our Label control
        xmlResultLabel.Text = htmlEncodedResult;
    }

As you can see the code above does the job of displaying the retuned xml from the webservice. It works. We can understand that XML because we are techie enough but imagine a normal user seeing a xml values on his screen? Yup. Not good. The best way to present data to a user is to show values in tabular form. A lot more pleasing to the eyes and much easier to understand. With that said let's start by replacing the Label control in the form with a DetailsView control. The new aspx page for our form should look like this:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Keith Rull's Consuming Web Services Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <strong>Symbol</strong><br />
            <asp:TextBox ID="symbolTextBox" 
                         runat="server" />
            <asp:Button ID="executeButton" 
                        runat="server" 
                        Text="Execute"
                        OnClick="executeButton_Click" />
            <br />
            <br />
            <strong>Result</strong>&nbsp;<br />
            <asp:DetailsView ID="stockQuoteInfoDetailsView" runat="server" Height="50px" Width="125px">
            </asp:DetailsView>
        </div>
    </form>
</body>
</html>

As you can see in the old code for the Click event we are able to get the XML and display it on a Label. What we need to do now is to read that XML string and assign it to a our DetailsView but there is one problem... The XML string needs to be converted to an object that supports IList or IEnumerable first before it could be loaded to our DetailsView.

To solve this problem I've decided to create this method that accepts an XML string and converts it to a DataSet.

    /// <summary>
    /// A function that takes an XML string and converts it into a DataSet
    /// </summary>
    /// <param name="xmlString">The xml string to tranform into a DataSet</param>
    /// <returns>The DataSet representing the values and schema from our xml string</returns>
    private DataSet XmlString2DataSet(string xmlString)
    {
        //create a new DataSet that will hold our values
        DataSet quoteDataSet = null;

        //check if the xmlString is not blank
        if (String.IsNullOrEmpty(xmlString)) {
            //stop the processing
            return quoteDataSet;
        }

        try{
            //create a StringReader object to read our xml string
            using (StringReader stringReader = new StringReader(xmlString))
            {
                //initialize our DataSet
                quoteDataSet = new DataSet();

                //load the StringReader to our DataSet
                quoteDataSet.ReadXml(stringReader);
            }
        }
        catch{
            //return null
            quoteDataSet = null;
        }

        //return the DataSet containing the stock information
        return quoteDataSet;
    }

Now we can modify our our executeButton_Click event

    protected void executeButton_Click(object sender, EventArgs e)
    {
        //get the execution symbol entered in the TextBox
        string executionSymbol = symbolTextBox.Text;

        //get the stock quote information
        string quoteInfo = GetStockQuoteInformation(executionSymbol);

        //create our quote DataTable
        DataSet quoteDataSet = XmlString2DataSet(quoteInfo);

        //assign the quote information to our DetailsView
        stockQuoteInfoDetailsView.DataSource = quoteDataSet;
        stockQuoteInfoDetailsView.DataBind();
    }

All we did was pass the xml string to the XmlString2DataSet function to retrieve a DataSet containing the stock quote information and then assigning that DataSet object to our DetailsView for display. Below is how the final form looks-like after our modification

Now that is more presentable! I hope I was able to share with you something useful. Next stop, we'll be building Master-Detail pages in ASP.NET ;)

Care for the code? Grab it here: KeithRull.ConsumingWebServices.Part2.zip (5.76 KB)

Thursday, April 17, 2008 5:27:06 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | ASP.NET | Tutorial
 Tuesday, April 01, 2008

Last week I showed you how to read an XML file, load it to a DataSet and assign those values into a GridView. Today I'll show you how you can read an XML file using the XmlDataSource object.

Let's assume that we have an XML file called Symbols.xml in our App_Data folder

that contains the following data

<?xml version="1.0" encoding="utf-8" ?>
<Symbols>
    <Symbol ExecutionSymbol="ATT" Name="AT&amp;T"></Symbol>
    <Symbol ExecutionSymbol="MSFT" Name="Microsoft"></Symbol>
    <Symbol ExecutionSymbol="GOOG" Name="Google"></Symbol>
    <Symbol ExecutionSymbol="CSCO" Name="Cisco"></Symbol>
    <Symbol ExecutionSymbol="IP" Name="International Paper Co."></Symbol>
    <Symbol ExecutionSymbol="MF" Name="MF Global"></Symbol>
    <Symbol ExecutionSymbol="Q" Name="Qwest Communications International Inc."></Symbol>
    <Symbol ExecutionSymbol="BMC" Name="BMC Software Inc."></Symbol>
    <Symbol ExecutionSymbol="WCI" Name="WCI Communities Inc."></Symbol>
    <Symbol ExecutionSymbol="SPY" Name="SDRs"></Symbol>
    <Symbol ExecutionSymbol="LEH" Name="Lehman Brothers Holdings Inc."></Symbol>
    <Symbol ExecutionSymbol="XLF" Name="Financial Select Sector SPDR"></Symbol>
    <Symbol ExecutionSymbol="QQQQ" Name="PowerShares QQQ TR 1"></Symbol>
    <Symbol ExecutionSymbol="IWM" Name="IShare Rus 2000 INDX"></Symbol>
    <Symbol ExecutionSymbol="GE" Name="General Electric Co."></Symbol>
    <Symbol ExecutionSymbol="MER" Name="Merrill Lynch Co., Inc."></Symbol>
    <Symbol ExecutionSymbol="BAC" Name="Bank of America Corporation"></Symbol>
    <Symbol ExecutionSymbol="INTC" Name="Intel Corp"></Symbol>
    <Symbol ExecutionSymbol="F" Name="Ford Motor Co."></Symbol>
    <Symbol ExecutionSymbol="QID" Name="UltraShort QQQ ProShares"></Symbol>
</Symbols>

and we want to load it to a GridView with no server-side code and a quick and easy way. The answer is to use the XmlDataSource object. The XmlDataSource control is an ASP.NET control that allows you to automatically read XML Data and make that data readily available to any ASP.NET control.

To start using this control, go to your Toolbox and drag the XmlDataSource control to your page.

Once the control is on the page it would popup a dialog that has configuration options for our XmlDataSource control. Click the "Configure Data Source" button to configure our XmlDataSource

A popup like below will come up that allows you to select the Xml file you want to your XmlDataSource object to read. It also gives you the option to select the XSL file. You can also specify an XPath expression to use to filter the data in our Xml.

Click the "Browse" button for the "Data File" option to select an XML file.

A new dialog will appear that will let you navigate the folder tree to select your desired XML file

Click "Ok" and you'll be taken back to the "Configure Data Source" screen. Click "Ok" again to finalize the XML data assignment.

Now that we have the file set in to our XmlDataSource control we need assign it to a control. We can do that by dragging a GridView control to our form.

Next, we need to assign the XmlDataSource control as the data source for our GridView. We can do this by selecting our XmlDataSource from the "Choose Data Source" dropdownlist.

Click "XmlDataSource1" and you will notice that our GridView was automatically updated and now shows the contents of our XML file.

Easy huh? Next up, Consuming Web Services in ASP.NET

 

Monday, March 31, 2008 11:15:13 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | ASP.NET | Tutorial
 Monday, February 25, 2008

I've been working on ASP.NET AJAX eversince it's beta days and the UpdateProgress and UpdatePanel has been my bestfriend since day one. I've learned a few tricks while using ASP.NET and today I'd like to share with you several ways to customize the look and feel of you UpdateProgress control with this sample solution. I have created a sample application that would demonstrate different ways to position your UpdateProgress control in the web browser. 

The samples included in the solution is as follows:

  • Sample 1

    The usual ASP.NET AJAX UpdateProgress control usage. This demonstrates the typical use of the UpdateProgress control in an application

  • Sample 2

    An ASP.NET AJAX UpdateProgress control positioned in the top right of the browser. (GMAIL like behavior)

  • Sample 3

    An ASP.NET AJAX UpdateProgress control positioned in the top right of the browser with a transparent gray background. (GMAIL like behavior)

  • Sample 4

    An ASP.NET AJAX UpdateProgress control positioned in the top right of the browser with a transparent gray background and the notification following the scrollbar position (fixed position).

  • Sample 5

    An ASP.NET AJAX UpdateProgress control positioned in the middle of the browser with a transparent gray background.

  • Sample 6

    An ASP.NET AJAX UpdateProgress control positioned in the middle of the browser with a transparent gray background and the notification following the scrollbar position (fixed position).

  • Sample 7

    An ASP.NET AJAX UpdateProgress control that uses the AlwaysVisibleControlExtender trick to place the progress notification at the top right of the browser.

  • Sample 8

    An ASP.NET AJAX UpdateProgress control that uses the AlwaysVisibleControlExtender trick to place the progress notification at the middle of the browser.

The project includes all aspx files, images and stylesheets that demonstrates effective UpdateProgress notifications. You can checkout the running sample of this ASP.NET AJAX project at the DevPinoy.org demo site

I hope what I shared with you can be useful in your daily life as a .NET developer. If you are interested you can download the source code for the whole project here: KeithRull.BuildingABetterAJAXLoadingNotification.zip (191.48 KB)

Monday, February 25, 2008 11:13:42 PM (GMT Standard Time, UTC+00:00)  #    Comments [4] -
.NET | AJAX | ASP.NET | Tutorial
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Keith Rull
Sign In
Statistics
Total Posts: 240
This Year: 37
This Month: 0
This Week: 0
Comments: 109
Themes
Pick a theme:
Ads
All Content © 2008, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)