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