Consuming Web Services from a NET Windows Forms Application

In this section, you'll create a C Windows application that uses the Mortgage Calculator Web Service to display calculated payments. The code for this project is separate from the CSharpASP ASP.NET project you've been working with in most of this book. First, create a new Windows Application project and name it MortgageCalculator. Although the interface uses Windows Form controls, it's essentially identical to the Web Form interface you just saw in the preceding section (see Figure 21.11)....

Comparing Options for Storing State

In this book, you'll use the inProc SessionState setting for all the examples that use sessions and except for the example in this section, that will be all the examples in the book. My main goal in this section is to show you that the performance differences between the various options is negligible until your Web server is under a heavy load. The section uses SQL Server to retrieve a table and then stores the resulting data set in the Session object for future use. Don't worry about the...

Referencing Script Files on the Server

The techniques you've seen so far are page specific. When you have generic client-side scripts, it's not a good idea to place them into individual pages, because if you need to modify them for any reason, you have to perform error-prone search-and-replace operations on all your pages. It's much more efficient, from a maintenance point of view, to place generic scripts in separate files on the server and reference them from multiple pages. For example, suppose you want to scroll the contents of...

Writing Client Script with Server Script

There's a difference between < script> tags intended for server-side script and < script> tags for client-side script. The ASP.NET framework assumes you want the script to execute on the client unless you specifically mark it as server-side script using the runat server attribute. You can include both server- and client-side < script> tags in the same ASP file, but there's a trick. Listing 20.2 shows an example. Listing 20.2 Combining Server and Client < script> Tags...

What Is SOAP

SOAP consists of two types of messages requests and responses and both are XML documents. The request XML document contains the following An envelope element that surrounds the SOAP payload (the message). The envelope is the root element of a SOAP XML document. A header (optional) that describes the type of SOAP message. A body (mandatory) that carries the method call name and parameter names and values. For example, suppose you have a Web Service that provides mortgage payment information....

Securing Your Server with SSL

Controlling access (implementing authentication and authorization) is one part of having a secured site. To secure your site fully, you need to encrypt the transmission of information between the client and the server. The .NET framework supports a large and growing set of cryptographic methods. The most common methods are RSA, named after Ronald Rivest, Adi Shamir, and Leonard Adelman, who first published the algorithm in April 1977. RSA is an asymmetric encryption. It uses a public key...

Using Trace Output

Implementing every possible event routine is useful for getting an overall picture of when events occur and it's the only way to step through the Global.asax events, but it isn't very efficient. Another way to get a good overall picture is to enable tracing. Tracing collects internal execution data and formats it so that you can get a good picture of what's going on in your page or application. You can enable tracing for a single page or for an entire application, and you can control whether...

Sending Email Messages

Problem Every morning, you want to count the number of requests in the IIS log made over the past 24 hours and send your boss an HTML-formatted report via e-mail. This time, there are two problems to solve. The first involves reading the IIS log, and the second involves sending e-mail. I'll deal with them in order because the first problem is much more involved than the second sending e-mail in .NET is simple. Understanding and reading the IIS log is vital for tracking your site's usage,...

Creating and Using Parameterized Stored Procedures

The qryStudentsOfMarshaFranklin query is not useful except for the single instance where you want to know the IDs of that teacher's students. You certainly wouldn't want to create separate queries for each teacher. If you were creating a SQL string to perform the query, you would probably create the query with a function call. For example, you might create a function that accepts a teacher's first and last names and returns the appropriate SQL query public String...

From Recordsets to XML

Shortly before Microsoft introduced shaped recordsets, XML started becoming recognized as an excellent way to represent relationships between data items, particularly parent-child relationships such as those found in most relational databases. XML can represent data ranging from a simple list of values to two-dimensional tables to extremely complex hierarchical sets. So, for example, you can represent the shaped recordset in the preceding section very easily, and in a way that's humanly...

Creating Stored Procedures

The ClassRecords database captures the relationship between Students, Teachers, and Classes. For example, one of the queries you wrote in Chapter 12 selected the StudentIDs of students who had Marsha Franklin for a teacher. FROM TeacherStudent INNER JOIN Teachers ON WHERE Teachers.LastName 'Franklin' AND Teachers.FirstName ,Marsha' In the next sections, you'll see several ways to turn the query into a stored procedure named Note When you first created it in Chapter 12, the ClassRecords database...

Sending Downloading Files

It's important for you to understand that only the client can initiate a file download. You can't write VB.NET code that downloads a file. For Web applications, it's best to forget the term downloading or at least, whenever you hear it, twist it in your head so that you think, Get the client to request the file. When you approach downloading from the client point of view, it becomes obvious that there are many ways to get the client to request the file. The most common method is to provide a...

Client Side Validation

Here's an example that performs client-side validation using the Validator controls. Create a copy of the Web Form ch5-1.aspx. You can copy files within the Solution Explorer just as you do in the Windows Explorer. Right-click the ch5-1.aspx file in the Solution Explorer pane, then select Copy from the context menu. Next, right-click the ch5 folder, and then select Paste from the context menu. That will paste a copy of the ch5-1.aspx file named Copy of ch5-1.aspx into the ch5 folder. Rename the...

Build a User Control

The simplest type of control you can build is a User control, which is essentially an ASPX page changed to have an .ascx extension. When you install .NET, it prevents IIS from displaying files with an .ascx extension directly, so users can't request your User controls by themselves. So that you can see all the differences, it's useful to attempt to change a Web Form into a User control (that is, change an ASPX page into an ASCX page). For example, create a Web Form called testChange.aspx, place...

Initializing the Soap Client

Initialization lets the SOAPClient read the Web Service's WSDL file so that it can create and parse the SOAP wrappers required to access the service. To initialize the SOAPClient, you specify the location of the Web Service by calling the soapClient.mssoapinit method. The method takes four arguments. The first required argument is the URL of the WSDL file for the Web Service you want to use. The other three arguments are optional and you may not know any of them immediately The public Web...

Create a Client Application

In this section, you'll create a Visual Basic 6 client application to consume the Mortgage Payment Calculator Web Service. Start a new Visual Basic 6 application and create a new Standard EXE project. Name the project MortgageCalculatorClient, and rename the default form frmMain. Build the user interface as shown in Figure 22.1. Figure 22.1 VB6 Mortgage-Payment CalculatorClient application interface Figure 22.1 VB6 Mortgage-Payment CalculatorClient application interface Note You must download...

Page Counter Example

Suppose you want to create a counter for your page that lets you know how often it is visited. The question is, where can you store the count information If you store it at Session scope, you need to keep the data in memory for every client instance accessing your application. If you store it at Application scope, the count will start over every time your application starts up. If you're going to create a counter that will persist across application instances, you need to store the data in a...

Aspnet Event Sequence

You need to know exactly when events occur and what events you can trap to take full advantage of the ASP.NET environment. You've already seen that you can begin trapping errors even before code execution begins in your page by writing code and setting a breakpoint in the Application_Begin-Request event. But when you first begin an application, that's not the first event in fact, it's not even the second. The only memorable way to discover how ASP handles events is to step through the code....

Simplifying the Special Offers Example

The special offers example you've just seen is an older way of doing things and it works but it certainly isn't the only way. This section contains some ideas and examples that have much the same result but use some .NET helper functions and different client-side techniques to display the special offers from the preceding section. ASP.NET can help you write complex client scripts. The first change you can make is to use a Page class method called RegisterArrayDeclaration. For example, you can...

The Data Reader Object

A DataReader object is a pointer into a table of rows that can return individual column values for the current row. You can't create a DataReader object directly. Instead, use the Command object's Execute-Reader method for example Create a connection object OleDbConnection conn null OleDBCommand cmd null OleDBDataReader dr null conn New OleDBConnection Get Northwind cmd new OleDBCommand SELECT FROM Customers, conn create the DataReader dr The last line creates the DataReader. The...

Other Http Application Events

In addition to the four main Application and Session events shown in the preceding section, the HttpApplication object exposes other events that are extremely useful and provide C Web applications with capabilities that were unavailable with previous versions of ASP. Although you can write code for these events in the global.asax file, you don't have to you can place code to handle the events in your Web Form class. For example, the HttpApplication.BeginRequest event fires whenever your...

The Http Application and Http ApplicationState Objects

C Web applications can have global values and objects, just as stand-alone Windows programs can have global variables containing values and objects shared between all classes. The HttpApplicationState object holds these values. Like most Web-based collections, it's implemented as a list of names and values in which the name is an indexed String array. You can't access the HttpApplicationState object directly. Instead, you reach it through an HttpApplication object. The ASP.NET runtime maintains...