Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Builder NE   

Advanced Configuration of a WebFigure

Overview

The advanced configuration gives the experienced .NET programmer (possibly a business service developer or front-end developer) flexibility and control in configuring system architecture based on differing needs. For example, with the WebFigureService and the Web page on different servers, the administrator can optimally position the MCR (for performance reasons) or place customer-sensitive customer data behind a security firewall, if needed.

In summary, the advanced configuration offers more choices and adaptability for the user more familiar with Web environments and related technology, as illustrated by the following graphics.

This section describes various ways to customize the basic WebFigures implementation described in Quick Start: Implementing a WebFigure.

Manually Installing WebFigureService

WebFigureService is essentially a set of HTTP handlers that can service requests sent to an instance of Internet Information Service (IIS). There are occasions when you may want to manually install WebFigureService. For example:

When you dragged the GUI control for WebFigures onto the Web page in Quick Start: Implementing a WebFigure, you automatically installed WebFigureService in the Web application file web.config.

To install this manually:

  1. Add a reference to WebFiguresService.dll from the folder InstallRoot\toolbox\dotnetbuilder\bin\arch\v2.0 to the project, (where InstallRoot is the location of the installed MCR for machines with an installed MCR and matlabroot on a MATLAB Builder NE development machine without the MCR installed).

  2. Add these lines to the <httpHandlers> section of web.config. This tells IIS to send any requests that come to the __WebFigures.ashx file to the WebFigureHttpHandlerFactory in the WebFiguresService.dll.

    <httpHandlers>
            <add 	path="__WebFigures.ashx"
                    verb="GET"
                    type="MathWorks.MATLAB.NET.WebFigures.
                            Service.Handlers.Factories.
                            Http.WebFigureHttpHandlerFactory"
                    validate="false" />
    </httpHandlers>
    

Retrieving Multiple WebFigures From a Component

If your deployed component returns several WebFigures, then you have to make additional modifications to your code.

MATLAB sees a WebFigure the same way it see a MWStructArray. WebFigure constructors accept a WebFigure, an MWArray, or an MWStructArray as inputs.

Use the following examples as guides, depending on what type of functions you are working with.

Working with Functions that Return a Single WebFigure as the Function's Only Output

 C#

 Visual Basic

Working With Functions That Return Multiple WebFigures In an Array as the Output

 C#

 Visual Basic

Attaching a WebFigure

After you have manually installed WebFigureService, the server where it is installed is ready to receive requests for any WebFigure information. In the Quick Start, WebFigureService uses the session cache built into IIS to retrieve a WebFigure, per user, and display it. Since a WebFigureControl isn't being used in this case, you need to manually set up the WebFigureService and attach the WebFigure. Add the code supplied in this section to attach a WebFigure of your choosing.

This method of setting up WebFigureService and attaching the figure manually is very useful in the following situations:

There are a number of ways to attach a WebFigure to a scope, depending on state (note that these terms follow standard industry definitions and usage):

StateDefinition
SessionThe method used by WebFigureControl by default, which is tied to a specific user session and cannot be shared across sessions. If you use IIS session sharing capabilities, you can use this across servers in a cluster.
ApplicationAvailable for any user of your application, per application lifetime. IIS will not propagate this across servers in a cluster, but if each server attaches the data to this cache once, all users can access it very efficiently.
CacheSimilar to Application, but with more potential settings. You can assign "time to live" and other settings found in Microsoft documentation.

Add the following code to manually attach the WebFigure, based on whether you are using C# or Visual Basic:

Setting Up WebFigureControl for Remote Invocation

After you drag a WebFigureControl onto a page, as in Quick Start: Implementing a WebFigure, you either assign the WebFigure property or set the Remote Invocation properties, depending on how the figure will be used.

The procedure in this section allows you to tell WebFigureControl to reference a WebFigure that has been manually attached to a WebFigureService on a remote server or cluster of remote servers. This allows you to use the custom control, yet the resources of WebFigureService are running on a remote server to maximize performance.

  1. Drag a WebFigureControl from the toolbox onto the page, if you haven't done so already in Quick Start: Implementing a WebFigure.

      Note   If you are running on a system with 64-bit architecture, use the information in Advanced Configuration of a WebFigure to work with WebFigures unless you are deploying a Web site which is 32-bit only and you have a 32-bit MCR installed.

  2. In the Properties pane for this control, set the Name and Scope attributes as follows:

    • Name ApplicationStateWebFigure

    • Scope application

        Caution   Always attempt to define the scope. If you leave Scope blank, the Session state, the Application state, and then the Cache state (in this order) will be checked. If there are WebFigures in any of these states with the same name, there can be potential for conflict and confusion. The first figure with the same name will be used by default.

    The pane should now look like this:

      Note   If you don't provide a root (usually the location of the load balancer), it is assumed to be the server where the page is executing.

Getting an Embeddable String That References a WebFigure Attached to a WebFigureService

From any server, you can use the GetHTMLEmbedString API to get a string that can be embedded onto a page, if you followed the procedures Manually Installing WebFigureService in Attaching a WebFigure.

To do so, use the following optional parameters and code snippets (or something similar, depending on your implementation). For information on the differences between session, application, and cache scopes, see Attaching a WebFigure.

GetHTMLEmbedString API Parameters

ParameterIf not specified...
ID Default MATLAB WebFigure (the MATLAB membrane logo).
RootThe relative path to the current Web page will be used.
WebFigureAttachTypeWill search through Session state, then Application state, then Cache state.
HeightDefault height will be 420.
WidthDefault width will be 560.

Referencing a WebFigure Attached to the Local Server

Referencing a WebFigure Attached to a Remote Server

Improving Processing Times for JavaScript Using Minification

This application uses JavaScript to perform most of its AJAX functionality. Because JavaScript runs in the client browser, it must all be streamed to the client computer before it can execute. To improve this process, you use a standard JavaScript minification algorithm to remove comments and white space in the code. This feature is enabled by default. To disable it, create an environment variable called mathworks.webfigures.disableJSMin and set its value to true.

Using Global Application Class (Global.asax) to Create WebFigures at Server Start-Up

In ASP.NET there is a special type of object you can add called a Global Application Class, Also known by the name Global.asax.

Global.asax classes have methods that are called at various times in the IIS life cycle, such as Application_Start and Application_End. These methods get called respectively when the server is first started and when the server is being shut down.

As seen in Quick Start: Implementing a WebFigure, the default behavior for a WebFigureControl is to store data in the Session cache on the server. In other words, each user that accesses a page using a WebFigureControl has an individual instance of that WebFigure in the cache. This is useful if each user gets specific data, but resources can be wasted in situations where all users are accessing the same WebFigures.

Therefore, in order to maximize available resources, it makes sense to move WebFigure code for commonly used figures into the Application_Start method of the Global.asax. In the following example, code written in the Web page initialization section of Attaching a WebFigure is moved into a Global.asax method as follows:

 C#

 Visual Basic

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS