In the process of developing an FMS, we often need to connect to a database on the FMS end and perform data query operations such as identity verification. You can use WebServices or netconnection objects or the netservices class. The difference is that netservices can return data of recordset objects, this example is a simple example of using netservices to connect to the flashremoting program. The focus of this example is
RunthroughThe recordset object is not used because of the data transfer process of "flash-> FMS-> flashremoting. The example is created using flash 8 + FMS 2.0.4 + ASP. NET 2.0.
Click here to download (74kb)>
I. Instructions for use
1). Create a virtual directory in IISRemotingappIn Asp.net, select 2.0 and put the content in the remotingapp folder in the example;
2). SetCrossdomain. xmlFiles are stored in the root of the IIS Site and must be accessible through http: // domain/crossdomain. xml;
3). SetFmsremotingtestCopy the folder to the application directory of the FMS. The default directory is "C: \ Program Files \ Macromedia \ Flash Media Server 2 \ applications \"
II. Key code analysis
1). testdemo. aspx
<% @ Page Language = "C #" DEBUG = "true" %>
<% @ Register tagprefix = "Macromedia" namespace = "flashgateway" assembly = "flashgateway" %>
<Macromedia: Flash id = "flash1" runat = "server"/>
<Script language = "C #" runat = "server">
Void page_load (Object sender, eventargs E)
{
Flash1.result= "Flashremoting server time:" + system. datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS ");
}
</SCRIPT>
Note that flashremoting is a special feature. Your page "testdemo. aspx "name" testdemo "is the method name. The code of the method should be written in page_load, and then the returned result is bound to a flashgateway object (" flash1 "in this example ") can be passed out. For more information about how to use flashremoting for. net, see other materials.
2). Main. ASC file on the FMS end
Load ("netservices. ASC"
);
//
Application. onconnect = function (client, _ name)
{
//...
This. acceptconnection (client );
//
Netservices. setdefagategatewayurl ("http: // localhost/
Remotingapp/Gateway. aspx ");
VaR conn = netservices. creategatewayconnection ();
VaR myservice = conn. getservice ("
Remotingapp", This );
Myservice.
Testdemo();
Application.
Testdemo_ Result = function (result_obj)
{
//...
}
//...
};
Pay attention to the bold parts,Load ("netservices. ASC");To be placed in the top row.
"Remotingapp"Is the virtual directory created on the front.
Conn. getservice ("Remotingapp", This); pay attention to this sentence. If your ASPX page is placed in a deeper directory, then in this sentence"Remotingapp", You need to convert the path to a namespace-like format, such as"Remotingapp. Folder ".
"Testdemo"Is the front sideTestdemoThe name of the. ASPX page. The function that receives data uses the format of "remoting method name" + "_ result.
3). fms_flashremoting.fla File
This is simple, just a little bit.
Iii. Notes
If the connection fails and data is returned, note the following:
1) security policy problems, placed in front"Crossdomain. xml"Is to solve this problem.
2). Web. configSystem. WebAre there:
<Httpmodules>
<Add name = "gatewaycontroller" type = "flashgateway. Controller. gatewaycontroller, flashgateway"/>
</Httpmodules>
Iv. test running effect of this example
For example:
V. Two simple problems encountered during development
1. How to view the trace information of the SAS server?
1) Open the Management Console of the FMS;
2). View applications-> {fmsremotingtest}-> livelog; for example:
2. How do I restart the FMS application?
Modified the program on the Windows Server, such as main. after ASC, You need to restart the application of the FMS to see the latest results. So if you change the code and cannot see the latest results, do not be annoyed. You need to perform this step.
1) Open the Management Console of the FMS;
2). Manage servers-> {fmsremotingtest}-> for example: