Preparing Your Development Environment for CardSpace
Your development environment will need some configuration before you can use CardSpace effectively. Before you do anything else, make sure that you have the Windows SDK installed. Within the Windows SDK, find the file WCFSamples.zip in the samples directory. In here, you'll find the technology samples folder containing CardSpace samples. Look at the UsingCardSpacewithIE7 sample note that CardSpace is not supported on earlier versions of Internet Explorer and open the setup.bat file, using...
The onError Event
This specifies the name of the JavaScript event handler that implements the code to execute whenever Silverlight encounters an error. The event handler will contain the current XAML element in its sender argument, and an errorArgs object containing details of the error. The errorArgs argument contains three properties errorType, errorMessage, and errorCode. For example, you could create an event handler for errors that provides details for runtime or XAML parsing errors like this function...
Data Binding in a Web Service
If you want to use this data in data binding to a GUI control such as a GridView control, you do it via the ObjectDataSource control. You can find this control on the Data tab of your Visual Studio Toolbox. Before placing it on the design surface, add a TextBox and a Button control. These will be used to pass parameters to the ObjectDataSource control at runtime. You'll see how to configure these using the ObjectDataSource wizard a little later. When you first place the ObjectDataSource control...
The onLoad Event
This specifies the name of the JavaScript event handler that implements the code to execute upon the Silverlight control loading and running properly. This event handler takes three arguments, control, userContext, and rootElement, which contain a reference to the Silverlight control, the user context of that control, and a reference to the root Canvas of the control, respectively. Here's an example function handleLoad control, userContext, rootElement alert I loaded successfully The...
The isWindowless Property
By default, the Silverlight plug-in runs inline in the page, meaning that HTML content flows around the plug-in. In many scenarios, you may want to write HTML content on top of the Silverlight content, perhaps to have an HTML form on top of your page, or to render a GIF or other graphics from a server that you don't want to inject into your XAML. This is possible using the isWindowless property. When set to true, HTML content can be written on top of the Silverlight content. The default is...
Silverlight Feature Highlights
While the high-level description of Silverlight as a browser plug-in that renders XAML and exposes a JavaScript programming model holds true, it leads to a number of questions around features and implications of building an application that uses such a plug-in. In order to answer these questions, consider some of the highlights of this plug-in It is a cross-browser, cross-platform technology. The Silverlight plug-in is supported consistently on Windows with the Internet Explorer and Mozilla...
How IIS Handles URLs
As you can see from the preceding example, the user types a URL into the browser, and IIS serves the HTML page in response to their request. The HTML code is then rendered by the browser as shown in Figure 6-6. When IIS received this request, the first thing it did was to examine this URL and establish the location of the content. First, it recognized that no port was specified on the URL, so it used port 80, which is the standard default HTTP port. If this server had been running on port 81,...
Partial Page Rendering
As you saw in the previous chapter, by storing page content and controls within UpdatePanels, partial page updates become possible. This is managed by the ScriptManager component, which delivers scripts that interact with the page life cycle you can see this in more depth in Chapter 3 . The ScriptManager has an EnablePartialRendering property that allows you to override this. By default, it is set to true, meaning that partial rendering is automatically enabled, and all UpdatePanel controls...
Using ADONET to Build DataDriven Applications
Now that you've installed and configured a SQL Server database, the next step is to learn more about ADO.NET and start building some applications designed to work with databases and data. You'll do this in two steps. First, you'll learn how to use the coding environment to create connections to the data and to retrieve data sets that you'll manipulate, and then you'll start looking at the graphical user interface GUI tools that provide this for you, as well as the server controls that you can...
The VideoBrush
One of the more powerful features of Silverlight is its ability to paint a surface with video. This is achieved using the VideoBrush. You will use the VideoBrush in conjunction with the MediaElement control which you will see later in this chapter . To use the VideoBrush, you add a MediaElement to your canvas, name it, and set it to be invisible and not accessible to the mouse. Then you simply set it to be the source for the VideoBrush. lt MediaElement x Name vid Opacity 0 IsHitTestVisible...
Adding a Simple Timeline Animation
Now, the designer is likely to want to have some kind of UI glitz happening. For this example, we will make the list box fade in from invisible as it slides in from the left-hand side. This is achieved using animation timelines. First you will want to create the trigger that fires when the button is clicked. You do this by selecting the button in the Objects and Timeline pane, and then the Event Trigger button in the Triggers pane. The IDE will create the default trigger, which is...
Using Visual Studio
Before we go into the architecture of ASP.NET, it's a good idea to create a simple ASP.NET application that can be used to demonstrate its architectural principles. This application is a multiple-tier application that consumes a back-end web service to expose a stock quote to the user. The examples in this chapter are built using Visual Web Developer Express VWDE , downloadable for free from Microsoft at http msdn.microsoft.com vstudio express vwd . For those who are not familiar with Visual...
The AddEventListener and RemoveEventListener Methods
One of the nice things about Silverlight is how it separates the design and developer artifacts to allow them to work together more efficiently. You can specify an event handler for an item by using a XAML attribute to define the name of the function that will have the code to run in response to the event. For example, you can use the syntax MouseLeftButton handleClick to declare that you want to use the JavaScript function handleClick when this element is clicked. The drawback with this is...
Using the DataList Control
The GridView is a large control with a wealth of functionality, and in the previous section, you barely scratched the surface of what you can do with it. If you just want to return a list of data and codelessly control how that list appears, you can achieve this with the DataList control. This control is a server control, found on the Data tab of your Toolbox. Make sure you have a fully configured SqlDataSource control on your web form, and then drop a DataList control onto the same web form....
WSSecurity
WS-Security is a set of enhancements to SOAP that allow you to specify how a message can be secured when being passed to and from a service. It can ensure that the message isn't tampered with, and that sensitive information, such as a password, is encrypted. The message is protected through authentication, confidentiality, and assurance of integrity. The original specification for WS-Security was drawn up by OASIS Organization for the Advancement of Structured Information Standards , and is...
Formatting a Date Using Locale
If you want to format a date according to the current locale on the machine, you must first set the EnableScriptGlobalization property on the ScriptManager control to true. You will also need to ensure that the culture attribute of the web site is set to auto using Web.config. Now if you use localeFormat and pass it a format string, the output will be formatted according to the current locale. For example, d gives MM DD YYYY in the United States and DD MM YYYY in the United Kingdom. var a...
WCF and Productivity
As mentioned earlier, there are many technologies available for building distributed applications. From Microsoft alone, you can use COM , .NET Enterprise Services, MSMQ, .NET Remoting, Web Services, and Web Services Enhancements WSE , to name just a few. Each of these requires different domain knowledge and different programming skills. WCF incorporates all of these into a single programming model, reducing this overall complexity and making it easier for the developer to focus on the business...
The createFromXaml Method
This extremely useful method allows you to add new XAML to the current render tree of the control. It takes two parameters the first is a string containing the XAML that you want to use, and the second is a namescope, which if used will create unique names for the tags in this string so that they do not conflict with existing element names within the XAML tree. When using this method, please note that you can only add new XAML elements that have a single root node so if you have a number of...
Putting It All Together Creating a Casual Game in Silverlight
In Chapter 15, you took a look at how to use Silverlight on your web page, and in this chapter, you've taken a look at the XAML and JavaScript used to build Silverlight applications. Now it's time to roll up your sleeves and put it all together with an example. Figure 16-6 shows the example a simple yet addictive memory game where you have to repeat a sequence of colors. Each time you succeed, the sequence will repeat with one new color added. See how high you can go before you forget the...
The Response Object
As you can imagine, if you can handle requests, you can also handle responses. This is done using the Response object, which can be used to write new output to the response buffer or to redirect the user to another page or site. So, for example, to write new content to the output buffer, you'd simply call its Write method, like this Response.Write New Content Or, to redirect the user to a new page, you can use this You can find more details here web.httpresponse VS.80 .aspx.
Understanding Page Processing
It is important to understand that there are a number of major differences between building web applications and building standard Windows client applications. If you are coming to web development from a Windows client development background, there are several aspects of web development that are significantly different from Windows client application development. Most Windows applications are designed to work with a single user, but web applications that don't scale to thousands of users are...
The ImageBrush
In addition to filling a space with colors or gradients, you can also fill one with pictures using the ImageBrush. It offers a number of attributes that can be used to set the behavior, in particular how you control the image's aspect ratio and tiling behavior. Here's an example of XAML to define filling a rectangle with an image using the ImageBrush lt Rectangle Width 200 Height 128 gt lt Rectangle.Fill gt lt ImageBrush ImageSource apress.jpg gt lt Rectangle.Fill gt lt Rectangle gt You...
Using the DataSet in a Web Method
To retrieve the data in a strongly typed DataSet, you use the corresponding data adapter. So, by creating a strongly typed DataSet, such as AddressData, you'll have a reference to the AddressDataTableAdapters collection. From this collection, you create an instance of an AddressTableAdapter, like this da new This table adapter implements the Fill and GetData methods that enable you to write and read data from the table, respectively. Because we specified a parameter ZIP , the postal code value...
An HTML Forms Example in ASPNET
The following example contains an ASPNET form, which is a server-side control that generates a client-side form, as well as a number of client-side form elements. If this is confusing, don't worry it will soon become second nature. I've deliberately chosen this complex scenario to demonstrate how ASP.NET makes it easy for you to mix and match server-side and client-side functionality to make your work as easy as possible. First, use VWDE to create a new web site. Open the default page that is...
Reflection in JavaScript
This is the ability to examine the structure of your program at runtime, enabling you to get information about an object, including where it inherits from, which interface it implements, and what class it is an instance of. You can determine whether an item inherits from a particular class by calling the inheritsFrom method on it. This method is implemented in the base Type class, and as such it is available to all your JavaScript classes. Consider the earlier scenario where we had two types of...
Creating Your Own CardSpaceSecured Web
Now that the SDK setup scripts have configured your environment by installing the certificates, registering the CAPICOM.dll, and editing your hosts file, you are ready to create your own CardSpace-secured web. Note that CardSpace-secured webs run on HTTPS, so you will create this application as an HTTP web application on IIS, not a file system site as you have been doing in earlier chapters in this book. Run Visual Studio with administrative permissions on Vista and select File gt New Web Site....
Using the SQLDataSource Control
When you are using Visual Studio or Visual Web Developer Express, open the Designer to edit any ASP.NET page. You will see a Data tab on the Toolbox. This tab contains the SqlDataSource control. Drag and drop it onto the design surface, and its Tasks pane will open see Figure 4-19 . Figure 4-19. The SqlDataSource control Figure 4-19. The SqlDataSource control This pane contains a Configure Data Source link. Selecting this link will launch the SQL Server Connection wizard see Figure 4-20 . The...
MediaElement Events
The MediaElement provides events that give you fine-grained control over writing media-oriented applications in Silverlight. It exposes the following events BufferingProgressChanged This event will fire when video is being buffered into the MediaElement. When playing back a streaming media source, a certain amount is buffered depending on bandwidth so that the overall playback is as smooth as possible. The event will fire when the buffer amount has changed by 5 percent or more, and when the...
Running Your Web Service
When you view the running web service in the browser, you'll see the ASP.NET web service description page. From here, if you select methods from the bulleted list, you can inspect and test the web methods that have been exposed using the WebMethod attribute. Should those methods require input parameters, the test page for that method will provide text boxes for you to enter the parameter values. You can see the test page for the default Hello World web service in Figure 5-3. Figure 5-3. Test...
Using Shapes in XAML
Many of the XAML elements used to make up your UI are XAML shapes that are composited into more complex shapes. The shapes that are supported by Silverlight are as follows Ellipse Draws a closed, curved shape. A circle is an ellipse with the same horizontal and vertical dimensions. Rectangle Draws a closed, straight-edged shape. A square is a rectangle with the same horizontal and vertical dimensions. Line Draws a line between the specified endpoints. Path Draws a series of connected lines and...
Implementing the Code
You can load the project into Visual Studio for editing. To do this, you use File gt Open Web Site, and find the site on your hard drive in the location that you created it using Expression Blend. The Page.xaml.js file should be used to create the code for the application. You don't have to use it, but it's good practice to put code associated with a XAML file in its code-behind. JavaScript programming can be done using delegate-based functions, as you can see in the basic code provided by the...
Adding a New Card to Your CardSpace Wallet
To add a new card to your CardSpace wallet, click the Add a card icon Create a new card, if you are using XP . You'll be taken to the next step of the wizard, where you can either create a personal card or install a managed card see Figure 10-3 . Figure 10-3. Adding a new card to CardSpace Figure 10-3. Adding a new card to CardSpace Select the first option, Create a Personal card, and you will be taken to the Edit a new card screen, where you can enter your personal details. Use as many or as...
Creating Controls at Runtime
Because controls are objects, and because the page controls are a collection, you can also create controls at runtime. So, if you consider the previous example, you can add a new list box to the bottom of the form quite easily with this code protected void Page_Load object sender, EventArgs e foreach Control ctrl in Page.Controls ctrl.ID theHead.Title Dynamically Created Title ListBox newListBox new ListBox newListBox.Items.Add new ListItem Item on my Dynamic List Page.Form.Controls.Add...
Installing the AdventureWorks Database
You can download the AdventureWorks database from http msdn.microsoft.com This will take you to the SQL Server 2005 downloads page, where a number of different downloads are available. Select the SQL Server 2005 Samples option to download the AdventureWorks sample database. Note that several versions are available for different hardware, so be sure to select the one that is appropriate for your setup. The preceding link takes you first to a registration page, but registration isn't necessary to...
Configuring Your Data Connections
Remember, your web service is connected to your database, so the first step is to change the web service connection from pointing to your local database to pointing to the server-based one. You do this by changing the connection string. Earlier, you had a connection string that looked like this Data Source localhost SQLExpress Initial Catalog AdventureWorks Integrated Security True You should change it to look like this Data Source servername SQLExpress Initial Catalog AdventureWorks Integrated...
Capturing Keyboard Input with the keyDown and keyUp Events
As only the root Canvas can receive focus, only the root canvas will receive these events. The keyDown event will fire when a key is pressed and the Silverlight control has focus. It raises two arguments sender and keyEventArgs. The first parameter will always contain a reference to the Canvas. The second will contain the necessary metadata to extract the key information. It exposes the following properties keyEventArgs.key This is an integer that represents the key that was pressed. It is not...
Programming WCF
Programming WCF is all about remembering the ABC of Address, Binding, and Contract. You'll step through some scenarios of building a WCF service that returns the address data from earlier, and add onto it with security, transactability, and reliability. This is a huge topic deserving of several books in its own right, but hopefully you'll glean enough from these sections to understand the big picture and get confident enough for a deep dive into the technology, should that be what you desire....
Layout in XAML
The lt Canvas gt element in Silverlight XAML is the workhorse for application layout. The Canvas is a drawing surface on which you place other canvas elements. You place its location using its Canvas.Left and Canvas.Top properties. These properties specify the location of any XAML object relative to its container. In addition, you can set the Z-order of the Canvas using the Canvas.ZIndex attribute. Z-order determines which item is drawn on top of another if multiple items are overlapping on the...
















