Integrated .NET technology

xiaoxiao2021-03-06  51

Integrated .NET technology

Download this article code download this issue magazine code to see resources

Visual Studio .NET provides tools that make developing business sites easier.

By alan gordon

With the technique introduced by vs.net, you can build an e-commerce website more easily than before. You can build a perfect web application with very little code, which is more flexible than a lot of confused scripts and HTML code used in most ASP applications. It is more easy to maintain.

figure 1.

Building architecture

I will show you how to build an online bookstore app, and we call this app .Net Books. This program is a bit mimicing the duwamish example in Visual Studio .NET. But it is also combined with service components. The service component is a .NET component that uses COM , increasing Microsoft Message Queue (MSMQ) and BizTalk Orchestration. (Note that the service component may only exist in the beta version.) Three-layer application (see

Figure 1) Combining several additional .NET technology, including Web Forms, Web User Controls, Web Service, Distributed Processing, Connection Pool, and Structure Strings. After reading this article, you will know how to combine a variety of .NET technology you can design, build and publish your own app.

The bookstore shows some books and some books that will not be published soon, which are related to .NET or related to .NET, such as XML, COM , SQL Server, and BizTalk Server. In fact, I found that the books placed on the "Today's Special Issue" is also useful to develop this procedure (see Figure 2). The .NET books application can also run on SQL7.0. It does not use any of the features of SQL Server 2000.

figure 2.

User discovers homepage

When the user has a order to .NET books, it writes the details of the order to the database and writes a private MSMQ queue a XML document describing the order. I have implemented a business process with Biz Talk Orchestration, and BizTalk Orchestration gets an order from the queue and then pays the payment according to the credit card information in the order.

BizTalk Orchestration is a subset of Microsoft BizTalk Server 2000 products. It is a tool for modeling, implementing and completing complex business processes. BizTalk Orchestration is a engine composed of XLANG-based language based on Visio 2000-based design tools and XLANG business processes.

image 3.

Browse book information

Internally, the .NET books business process uses a random number generator to approve some orders and reject some orders. This business process updates the status of the order to show the order being successfully paid or rejected by the customer's credit card.

When the user accesses .Net Books, he or she can search for a book based on some identification information such as title or author (see Figure 3). The search results returned to the directory that meets the conditional books. When the user clicks on the title, we will connect to the page about this book more detailed information. If the user decides to purchase this book, click "Add to Cart" to join the book to the shopping cart, and then we have arrived at the shopping cart page (see Figure 4). Here, users can see the currently selected books, can edit the number of books, and set the quantity to 0 to delete the book. When the user has made a decision, he or she chooses to submit the connection. When the user has not logged in, this connection prompts the user to log in. When the user has already logged in, he will be taken to a three-step ordering guide, enter the mail order address and credit card information here. The third step shows that the user has completed the order, when the user clicks on the confirmation button on this page, the order is submitted and started. When the customer submits the order start processing, the application updates the database information of this order, and the XML document describing this order is sent to the message list. These two actions are executed during distributed processing. If any one fails, the process will be returned, in other words, if the XML document is not sent to the information queue, the database will not be updated, and vice versa.

Establish a search

Figure 4.

Add a book to the shopping cart

Although the .Net Books program itself is not unique, its new is intended to use .NET Framework and vs.net make it easier to develop this application. All the pages in this app include in a C # network application project called DOTNetBooks. This project includes 10 Web Forms pages, two web user controls, and a C-class for executing a shopping cart program. The default page-DEFAULT.ASPX-contains all search performance. If you choose to search from any page, whether the user-defined search is searched, or searches in a predefined directory, you will be reset to the default page. The search string of this page is transmitted to determine the type of search (eg by title) to search for data. For example, the following address is used to search all books containing C # in the title. (see

Listing 1)

http://localhost/dotNetBooks/default.aspx? searchtype = Title & SearchData; = C #

Search controls will appear on most pages of the website, which is used as a web user controls. Web User Control is a small fragment of the ASP.NET Web from FROM code. It can be easily reused by other pages. Select to add Web User Control in the project menu to add Web User Control. This will have a form in VS.NET, you can edit this form like editing other Web Form. Then, VS.NET stores this form into files that are expanded as ASCX. Use it in web user control to the client's Web Form, which, vs.net will pick up the code to the top of the client Web Form and register the web user control in the client web form.

<% @ Register tagprefix = "dotNetbooks" tagname = "search" src = "searchControl.ascx"%>

VS.NET also adds the label of the Web User Control under the client Web Form to:

DataList, DataGrid and Reapeater controls are the most powerful controls in the Web Forms tool library. Every place in which you list can be displayed with DataList, including a list of directory in the search control, and a list of books obtained after searching. The shopping cart page uses the DataGrid control. You can use the DataList control in a variety of different places, but you can use its local or data binding most powerfully and flexibly. The most powerful and flexible place to use data binding is in the project template. The project template allows you to define a small HTML code to display each row of data in the data source (see List 2). For example, the code in Listing 2 represents an item template for displaying a list of books. This template defines the HTML table. The table contains an image and two line hyperlink text. The DataBinder.eval method is used to display the data obtained by the data source on the template. For example, the following code (excerpt from the list 2) shows how to bind the picture of each book to the image control of the project template.

Chapter 3 of "ASP Preview" is discussed in DataList, DataGrid, and Repeater controls.

There is a shopping cart with almost all e-commerce websites, when the customer is browsing on the website, explains if they want to buy, they can join the item to the shopping cart. Customers can also modify the number of goods in the cart or delete them. If you use ASP to establish an application, there are two ways to implement shopping cart. It is easy to store the shopping cart in Session. Of course we assume that your code is no problem. Unfortunately, the Session object is executed as a stored data structure, which is placed in the process of IIS. This will cause two main issues: First when the IIS process fails or off, all session objects will be lost; then, running websites on the server will become more complicated, because Session is bound to generate session Machine's IIS process. In order to use session in the web page, you must ensure that the client always returns to the same server, otherwise the client's session will be lost.

ASP.NET solves these issues. Now, you have three options to store session. First, in the process of being placed in the process of network services on the current host by default, this is the same as ASP. Second, Session can store a separate process of network services, which is on the machine of your server group. Other machines of your server group can also access this process. Finally, you can store in SQL Server. You can use the configuration file in your network program (config.web) to select where your session information is stored. You write information to the session or read information from the session, will not change according to where you choose to store the session object. The following code shows how to retrieve the shopping cart in the web page in the .NET books.

Public Cart getShoppingCart ()

{

// Try to get the cart from session

CART ShoppingCart = (CART) (SESSION ["ShoppingCart"]);

IF (null == shoppingcart)

{

// if there is no cart, crete it now

Shoppingcart = new cart ();

// save the cart for lating us

Session.Add ("ShoppingCart", ShoppingCart;

}

Return ShoppingCart;

}

This logic is very familiar with people using ASP. Rob Howard wrote a wonderful article on ASP.NET Session State (see resources). Similarly, you can also see an article called "session stat" in the .NET Framework Developer Wizard. For this application, I built a class called Cart, which provides a convenient way to change the number of goods in the shopping cart, send the shopping cart to the server (apply orders), and empty the shopping cart after the order (see Table 1). The data of the shopping cart is stored in a strict data type. This type is from the XML Schema (XSD) file I have established.

In order to generate a strict data type from the XSD Schema file, first, you must add the XSD file to the VS.NET project. When you double-click this file, VS.NET displays this XML Schema file in a visual editor (see Figure 5). Right-click the XML Schema Editor Select Generate DataSet to create a strict data type to match Schema. You can handle this data with methods of processing data from the database. When your data is used to use XML or XMLData properties, it creates an XML document that uses the XML Schema generated by the data set.

This feature contains another, ie integration with BizTalk 2000. You can choose a BizTalk Schema or create an XML Schema in the BizTalk Editor, read in vs.net, and then create a strict data type of data type according to this schema. I plan to use this method, but because BizTalk 2000 Beta generates XDR Schema, there is no way to implement. In the .NET Framework, it contains XML Schema definition tools that convert XDR Schema to XSD Schema (see information about XSD.exe in the .NET Framework SDK).

I tried to use this method, but it turned into this Beta version of BUGS. Finally, I gave up this idea, and I have established a simple XML Schema with the VS.NET editor. When the user gets a order, the application sent the data set to the Web Service. The Web Service extracts the order information from the dataset, and then invokes the stored procedure into the database into the database. Web Service uses the XML attribute in the data set to return an XML document and send this document to the list of Microsoft information.

Security Mechanism

Business applications .NET reduces development costs by using VS.NET and .NET Framework you can flexibly and efficiently develop B2B or B2C applications. What tools you have to know are available, what they can do, how to combine them to simplify the process from concept to development. Understand the relationship between different functions of .NET can strengthen your ability to manage your project. Safety, especially identification and authorization, more easily implemented in ASP.NET than ASP. Identification is the process of proved his or her identity to a computer system. Typically, the user provides a certificate including username and password combination. Authorization is the process of restricting user access to identity-based resources. Most e-commerce websites allow users to browse and add goods to the shopping cart by identification. It is only necessary to identify when the user is under orders, and the user is required to enter the username and password. Using ASP You can explain whether the user logins in the session to implement the identification. If the user browses to a web page that needs to be authorized, then connect the user to the landing page. If the user enters a valid username and password, you connect users on the webpage that you plan to visit, and set the Boolean flag in the session to explain that the user has identified.

ASP.NET provides all of these identification functions. You must first choose a getting identification method. You can choose: Windows, Passport, Forms (called cookie in Beta 1) and None. (See "ASP.NET Identification" in the resource for more information on the selection. Use Forms in the .NET books program. Select the ASP.NET authentication method in your config.web file. The following code shows how to select an Forms identification. In this example, you confirm that the system will use the cookie name (DOTNetbookScookie) and the address (login.aspx) that is re-directed when the user needs to be authorized. Once you have selected the identification method, you can limit users access to a specific page with the following method in the config.web file:

Here you refuse anonymous access to Checkout1.aspx (the first page of the Order Wizard). Therefore, users who have not logged in will be automatically referred to as Login.aspx. In Login.aspx, users can enter usernames and passwords. Then Login.aspx will call the login method in the .NET Books Web Service. If the username and password exist in the database, the login method returns a success code and connects to checkout1.aspx, otherwise, an error message will be returned.

The business logic of the ISS website is separated by the commercial logic. Net books website is implemented as a web service. You can discover all the code for this web service from the DotNetBooksWebService (see Table 2, downloading code from .NET Magazine Website). Divide this website's business logic into network services, which makes it easier to reuse these business logic in your website. For example, build a book club website, which use our network services to search and order books. There are many articles now introduce how to build a network service in .NET (see my Visual C development journal in the resource), so I will no longer introduce how the basic knowledge of network services. However, there are few articles on how to use COM services, such as distributed processing and object pool (Object Pool) (and message queues in .NET), I will show how to use these technologies in your network service.

The following code shows how to transform the .NET class into a service component, and the black body represents an important part.

Using system.enterprises ;;; [transaction (transaction (transaction (TransactionOption.Required)]

Public Class Books: ServicedComponent

{

[WebMethod]

[AutoComplete]

Public DataSet getBooksbyTitle (String Title)

{

// ...

}

}

In order to establish a service component, you should first refer to the System.EnterpriseServices collection, use the "Using" declaration to increase the reference. Then, you have to add a feature to the service component to show which COM service you want to use. In the documentation of the System.EnterpriseServices namespace, you can find a full list of existing COM related features. In this example, I use the transactional feature that indicates that this class requires transaction processing. Service components must also inherit a class called ServicComponent, which can also be found from the System.EnterpriseServices name space. The Books class uses the COM feature called AutoComplete. This feature calls setComplete () automatically completes the commodity transaction when the method successfully returns, and calls setabort () when the method throws an exception.

When the client instantiates a service component class, if the COM application does not exist, the Common Language Runtime (CLR) establishes a COM application to run this class, then add the service component and its characteristics to the COM application. You join the following code to your collection file (in the vs.Net project's assemblyInfo.cs), these code can control how the COM application is established, or affect the application layer COM feature used in the COM application: [Assembly: ApplicationName ("DOTNetBooksApp")]]

[assmbly: ApplicationActivation (ActivationOption.Library)]

[Assembly: Description ("A COM Application To Test .NET Service Co.")]]]]

Here are the DotNetBooksApp COM app, and the class library is used to activate.

If you build a service component class at the same time it is also a network service, you need to pay attention to the following three points: First, this class cannot be inherited from the WebService as most of the network services. You can't inherit from WebService because C # can only inherit from a separate class, and the service component class must inherit from the servicedcomponent base class. If you don't inherit from a WebService base class, you cannot access Session, Application, and Context objects, but other network service functions can be used as expected. Second: If you want to use the service component to implement network services, you must add the collection code containing the service component to the public assembly Cache (GAC) before using the service component. This code allows IIS to discover service components classes. Service components must have a compelling name. You can use a shared naming tool (sn.exe) to get a striking name, then add the name to your collection by adding the following code to your collection information file.

[Assembly: AssemblyKeyFile ("FileNameForKey"]]]]]

The third point is that VS.NET will not display network services from service components in its designer. You will see an error message: "Base class system.enterprises .servicedComponent cannot be designed." This error does not prevent you from seeing the code of the network service. If you have to use the designer, then you will save it as a service component until you no longer use the designer.

If you want to use distribution, but don't want to build a service component, you can also set the TransactionOption property in the webmethod feature as you have shown in the summary form.

Public Class Books: WebService

{

[WebMethod (TransactionOption = TransactionOption.Required)]

[AutoComplete]

Public Dataset getBooksBytitle

String Title

{

// ...

}

}

Using this method, you can use the network service base class that can access Session, Application, and Context objects.

Remember, whether you distribute the distribution in the TransactionOption property you pass through the service components or through the network service feature, you have to coordinate the processing involving multiple resource manager, including SQL Server and MSMQ, in our example is Single network service. There is currently no organization to coordinate processing of multiple network services. This feature requires extended to Simple Object Access Protocol (SOAP). Your network service uses ADO.NET to read data from the database and write data to the database. Most methods in the network service are to send 0 or more parameters and return to the client to return a search. In order to maximize code, I built a method called getDataSetFromstoredProc. This method includes most ADO.NET logic that calls the storage process to return data sets (see list 3). The GetBookSbyisbn method has established a parameter to give this parameter correct type and value, then pass this parameter and the name of the stored procedure to the getDataSetFromstoredProc method (see List 4).

The most complicated method in web services is an InsertOrder () method. If you download code from the .NET Magazine website, you can see this method. When the user confirms the next order, the client calls this method. This method performs two main functions: add orders to the database and send the XML document to the information queue.

In order to maximize implementation and scalability, I built a stored procedure, also called INSERTORDER. This stored procedure allows us to add users and more information to the database at a time. The InsertORDER stored procedure accepts customer ID, communication address, credit card information, and total number of orders and qualified fields containing order information:

Item [1] .id, item [1] .quantity,

Item [1]. UNITPRICE / ITEM [2] .id, item [2] .quantity,

Item [2] .unitprice

INSERTORDER stored procedure parsing strings and adds the order details to the Database's OrderItems table. InsertOrder () method Take the shopping cart as input information. This method extracts customer ID, communication address, and credit card information from the data set. The order details information is then converted to a string of the format. Then passenger strings and order parameters to the INSERTORDER stored procedure.

When the INSERTORDER () method adds the order information to the database, it writes the XML document containing the order information into the message queue. Network Services Check if the private message queue "devdotnet" exists before sending a message. You must build this queue on the host running the network service.

The .NET framework includes a number of message converters that you can use them to write the .NET object to the message queue. In this app, we use ActiveXMessageFormatter because we use this converter to send to the queue to be easily accessible in the BizTalk Orchestration business process.

Using BizTalk Orchestration I decided to use BizTalk Orchestration to perform payment authorized business processes. This business process uses a random number generator to approve some orders and reject other orders. It then updates the status of the order to display whether it is successful. You must have the final version of BizTalk 2000 Server to use the payment authorization business process, but if you don't, other parts of the .NET books application will continue to work.

Figure 6.

Business process modeling

BizTalk Orchestration is a tool for helping modeling, executing, and completing complex business processes (see

Figure 6). The key to this technology is XLANG, XLANG is an XML language used to describe the business process. Using BizTalk Orchestration is very simple, business analysis home BizTalk Orchestration Designer creates a process, which is a special template Visio 2000. The developer then establishes COM objects, scripting components, and message queues to perform business processes. Developers connect these objects, scripts, and message queues to the flowchart. The data is then defined between the object, the script component, and the queue, and compiles the Visio map to become a xlang file. Then developers can perform the XLANG file using the XLANG schedule engine in the BizTalk service. In order to run the business process, it is sure that you have established a DEVDOTNET message queue and then build a pair of orders on the website. The INSERTORDER method in the .NET books network service sends an order to the message queue. From Start / Programs / Administrative Tools / Turn on your computer, verify that the order exists in the DEVDOTNET message queue. Write down the order number in the queue.

Now let's enter the RunSchedule directory below this article code in the BizTalk subdirectory. Run the executerderprocess.exe file. Download the Order XLANG file (ORDERPROCESS.SKX), click Run the XLANG Process button. You will see a message shows that the business process is running successfully. When you go back to the DevdotNet message queue, the first message has been removed from the queue. Look at the order table in the database, you will see the status of the order number from the message queue has changed. If it is 1, it indicates that the credit card is authorized to pay, if it is -1, indicate the credit card Refused. The code of this article includes a Word document, step by step, describe how to build a business process in BizTalk Orchestration.

There are still many jobs in the project. The web page can become more beautiful. If the website can be redesigned by an experienced website designer, I will be more interested. I have no time to implement account management capabilities. In other words, the user should be able to see an order that is not submitted, and the address and transaction information can be changed. Database design can also support customers to fill in multiple addresses. You can change the interface based on these expansions. You can also try to perform distributed processing, replaced, using the WebMethod property using the WebMethod property of TransactionOption features.

About the Author: Alan Gordon is FieldCentrix project manager. FieldCentrix mainly develops Internet-based software applications in the service industry. He taught the courses related to COM in UCLA EXTENSION, and the author of "The Com and Com Programming Primer (Prentice Hall, 2000)". At present, he is writing .NET book for COM , this book will be published by Apress 2001. You can contact him through agordon@fieldcentrix.com.

转载请注明原文地址:https://www.9cbs.com/read-116772.html

New Post(0)