Custom Class-based Web Service

Custom Class-based Web Service

Web Services can also be based on custom classes. The code contained in the Web Matrix Custom Class template uses OrderDetails and OrderItem classes to detail orders:Both classes (OrderDetails and OrderItem) have pubic variables that are decorated with attributes that specify how the property should be serialized. The Web Method of the custom class, GetOrderDetails, returns an instance of the OrderDetails class, which is serialized according to the specified attributes.In addition to the standard HTML and ASP.NET Server controls, there are plenty of other controls that can be used with Web Matrix. The market for third-party controls is growing quickly, and these can be added to Web Matrix by customizing the Toolbox. You can even create your own custom controls and add them to the Toolbox. There are also two additional sets of controls supplied by Microsoft: the Mobile Internet Toolkit Controls for creating applications for mobile devices and the Internet Explorer Web Controls for creating rich content for IE.

Mobile Internet Toolkit Controls

Support for mobile devices is just as good as for traditional browser pages, but you will need to install the Mobile Internet Toolkit first. You have the choice of a Simple Mobile Page or a Simple Mobile User Control, both of which look like this:By default this page will support all mobile devices, but you can select the Customization Mode, which allows you to target specific implementations of devices. Although the designer differs in look, its use is exactly the same as for other pages. You drag and drop the mobile controls onto the design surface, and then add your own code. For example, we can add a selection list for pizzas:Here we’ve added a SelectionList control to the form and set its SelectType property to MultiSelectListBox, and the DataTextField property to name (for the name of the pizza). The code to run when the form loads is:The Internet Explorer Web Controls are a set of server controls that provide rich DHTML support for use in Internet Explorer (version 5.5 and above). These can be accessed by customizing the Web Matrix Toolbox. You can then use them as you would any other control, by dragging them onto the design surface. Of the four controls supplied in the IE set, only the TabStrip has designer support – the rest must be customized in either HTML or Code view.

Building and Use a Custom Control

Building custom server controls can easily be done using Web Matrix, since such controls are just classes. However, Web Matrix doesn’t support the automatic building of class files, or some of the advanced features that you might want to use when creating custom controls, such as the ability to embed resources such as a bitmap.Despite these limitations, and the fact that Web Matrix is designed primarily for editing ASP.NET pages, it’s still a fine choice for creating custom controls. Here you can see a simple site content control I’ve created (which supports templating) by adding a class and usingthe code editor:Since this control will be added to the toolbar the control needs a strong name, which needs to be created manually using the sn.exe utility (you can find more information about sn.exe in the .NET Framework SDK documentation). Then we can compile the class manually, and use the Add Local Toolbox Components option on the Tools menu to add this control to the Toolbox:

Just like ASP.NET, Web Matrix obtains most of its run-time settings from a configuration file. This file, named WebMatrix.exe.config, is located in the Matrix program folder: \Program Files\Microsoft ASP.NET Web Matrix\version\This folder also contains a file named ClassBrowser.exe.config, which contains the run- time settings for the Class Browser tool. The ClassBrowser.exe.config file is similar in format to the corresponding section of the WebMatrix.exe.config file.The format and content of Web Matrix’s configuration files is likely to change as the product develops, but the current version of WebMatrix.exe.config contains the following sections. Note that « saturn » was the early project/development name for Web Matrix, and is still used internally:If you find that your changes to the WebMatrix.exe.config file are not picked up when you next start Web Matrix, you should manually delete the Matrix.settings file in order to force Web Matrix to re-read the WebMatrix.exe.config file and generate a new WebMatrix.settings file when you close it down again. Note that this will remove any assemblies that you have added to the Classes window using the Customize dialog. To permanently add assemblies to the Classes window, you must edit the WebMatrix.exe.config file as shown in Customizing the Classes Window.

Cours gratuitTélécharger le document complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *