An attempt to wrap a third-party component to provide a service with ASP.net

Source: Internet
Author: User
Tags config exception handling execution expression file system reference
asp.net many of the application's authors provide programmers with components that can be reused in other programs. We typically introduce these third-party components into our programs and invoke the Out-of-the-box functions to achieve relatively complex functionality. In fact, we can also publish functions in third party components over the network to provide services more easily for more users.

For. NET Development, you can package Third-party components through asp.net (to people) or Web Service (to machine) technology. The following is an example of releasing the Execute function in the MATLAB component with asp.net. The prerequisite is that MATLAB is installed on the server.

Create a new ASP.net site in VS2005, click on the Solution Explorer pane's Site directory to select Add Reference, add matlab COM components: MATLAB application (version x.x) Type Library.

Add a TextBox, a button, and a literal control to the Web page separately. The textbox is used to enter the expression, the button determines the execution, and literal the output. Add the following event code to invoke the Execute function in the MATLAB component to execute the MATLAB statement:

Protected Sub button1_click (ByVal sender as Object, _

ByVal e as System.EventArgs) Handles Button1.Click

Dim matlab as New Mlapp.mlapp

Dim Strmatlab as String

Strmatlab = TextBox1.Text

Dim strresult as String = matlab. Execute (Strmatlab)

strresult = Strresult.replace (CHR), "<br>"

strresult = Strresult.replace ("", "")

Me.Literal1.Text = Strresult

Matlab. Quit ()

End Sub

To run this site in VS2005, enter an expression in the page that appears, such as "Dsolve (' dx=x^2+5 '), and the result will appear when you click the button:" ans = 5^ (1/2) *tan (5^ (1/2) *t+5^ (1/2) *c1) ". However, if you publish this site with IIS, the runtime will have an error, prompted because ASP.net does not have permission to create the component. According to the error prompts, we need to add a sentence to the Web.config file in the website:

<identity impersonate= "true" Username= "xx" password= "xx"/>

The user specified here should be a user with relevant permissions on the server side. If not specified, authentication is performed on the client page. Of course, it is not safe to save the username and password in the web.config, and to encrypt it in a real application.

In this regard, we completed the MATLAB expression evaluation function of the network release. You can notify the installation of MATLAB is not a friend to login to your site using the powerful computing function of MATLAB. (Note: This example is for demonstration only, the powerful MATLAB statement and Toolbox is enough for remote users to access your file system through this web page.) )

Because of the nature of the HTTP protocol and the characteristics of server-side execution, this wrapper for third-party components is generally appropriate for publishing data processing functions and not for publishing control functions. At the same time, this method is not very suitable for the real-time or need to save the state of the service. For security reasons, we can also package the third party components two times, adding data filtering and exception handling.

The principle is very simple. I hope you can discuss with me the value of this scheme in practical application.

Reference:

1, Lee Honggen, application of MATLAB algorithm in. Net

(http://www.microsoft.com/china/community/Column/25.mspx)

2, Matlab 7.1,matlab Web Server related help documents



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.