Flash + asp.net webServices getting started
Authentication when WS is called in Flash _ 1: Hello
Because the WS constructor is based on Asp.net, which is based on Asp.net.
Flash as the UI Layer has the following benefits:
1. Independent from specific platforms
2. lightweight, allowing you to easily construct rich client programs.
3. Better user experience.
However, Flash cannot directly interact with the database when building complex applications, and must rely on other middle layers, such as FlashRemtoing and PHP. Each method has its own advantages and disadvantages.
When Flash interacts with Asp.net, the best way is to use WebService.
The following is the first simplest example, starting from the server:
<% @ WebService Language = "c #" Class = "wsLearn. test" %>
// This statement indicates that this is a WebService.
Using System;
Using System. Web;
Using System. Web. Services;
// The class that must be referenced when creating WS.
Namespace wsLearn {
// The namespace of ws "test"
[WebService (Namespace = "http://www.dxlschool.com/ws")]
Public class test: System. Web. Services. WebService {
Public test (){
// Do nothing
}
[WebMethod]
Public string hello (){
Return "Hello !! ";
}
In this way, the simplest WS structure is completed. It only contains a method hello and stores it in your virtual directory that supports asp.net, enter an address in the browser to view the running status of the ws.
For example, in IE, enter the following url: http: // localhost/ws/test. asmx
The following prompt is displayed in IE:
Test
The following operations are supported. For formal definitions, see service description.
Hello
Click "hello". ws returns an XML file.
<? Xml version = "1.0" encoding = "UTF-8"?>
<String xmlns = "http://www.dxlschool.com/ws"> hello !! </String>
Next we will call this hello method in Flash.
I am using the Web service class to call the ws hello method.
/**
ActionScript Source File -- Created with SAPIEN Technologies PrimalScript 3.0
@ Class wsSessionTest_1
@ Package wsSessionTest_1.as
@ Author JimLee
@ Codehint
@ Example
@ Tooltip
*/
Import mx. services .*;
// Import the services Package
Var myws: WebService = new WebService ("http: // localhost/ws/test. asmx? Wsdl ");
// Use the WebService object myws to reference ws
// Define the processing after the ws method hello callback. The result parameter is the value returned by the ws hello method.
// ShowSession_lb: lable component
Function hello (result ){
ShowSession_lb.text = "message returned from ws:" + result;
};
// TestSession_bt: button
// Use the PengingCall object op_1 to proxy the ws hello method in flash
This. testSession_bt.onPress = function (){
Var op_1: PendingCall = myws. hello ();
Op_1.onResult = hello;
}
Note that if the Web service class is only used in Flash Professional and you want to use the Web service class in your work, you must import the Web service class package. Otherwise, there will be no response.
Click "window-Other panel-Public Library-class", open the public library "class", drag the WebSessionClasses component to the stage, import the Web service package to Fla, and then, you can delete an instance of the WebSessionClasses component on the stage.
Next, we can test your swf. If it doesn't exist, the lable component showSession_lb will show "message returned from ws: hello ". However, please note that you can leave enough length for your lable component to display information!