Authentication when WS is called in Flash _ 2: Input and Output

Source: Internet
Author: User
Tags wsdl
Next let's take a look at the Web service class in flash.
The Web service class exists in the mx. services package. To be able to use the Web service class at runtime, The WebServiceClasses component must be located in the library of the FLA file. The Web service class includes four key classes: WebService class, PendingCall class, Log class, And SOAPCall class. The WebService and PendingCall classes are directly related to ws calls. The WebService constructor can return the specified WebService object in Flash Player. As shown below

Var myWebServiceObject: WebService = new WebService (wsdlURI );

The wsdlURI parameter points to the referenced Web service address, for example, "http: // localhost/ws/test. asmx? Then, use the PendingCall type callback object to process the results of the method specified in ws in the onResult method of the PendingCall callback object. For example:

Var op_1: PendingCall = myws. hello ();
Op_1.onResult = hello;

Let's take an example to see how the Web service class works.
Note: This example demonstrates that ws accepts simple numeric types, simple Date and Time types, bool type, simple name and string types, and Array type parameters from the client and returns the value.
First, construct the ws on the server side.
Open a text file and declare a WebService Processing Command
1. as follows:
<% @ WebService Language = "c #" Codebehind = "sample2.asmx. cs" Class = "wsLearn. sample2" %>
Name sample2.asmx in the virtual directory http: // localhost/ws.
The Language attribute indicates the programming Language used to develop XML Web services. You can use any language compatible with. NET (such as Visual Basic. NET or Visual C #) to create XML Web services. The supported code files associated with the. asmx page are indicated by the Codebehind attribute. Class Attribute indicates a Class that supports the XML Web services function in code files.
2. Create a new cs document: Write the following code:
/* ===================================================== ======================================

C # Source File -- Created with SAPIEN technology Primalcode 3.0

NAME: sample2.asmx. cs

AUTHOR: JimLee, Dxl School
DATE: 2004-10-7

COMMENT: This example demonstrates the simple type, date, and time of accepting numbers from the client in ws.
Type, bool type, name, string simple type, and Array type parameters and return values.

========================================================== ===================================== */

Using System;
Using System. Web;
Using System. Web. Services;

Namespace wsLearn {
[WebService (Namespace = "http://www.dxlschool.com/ws/", Description = "Example 2, demonstrate the passing value of the ws method", Name = "s2")]
Public class sample2: System. Web. Services. WebService {
Public sample2 (){
//
}

[WebMethod]
Public string GetUserName (string tName ){
Return "hello," + tName;
}
}
}

Note the following code:
[WebService (Namespace = "http://www.dxlschool.com/ws/", Description = "Example 2, demonstrate the passing value of the ws method", Name = "s2")]
WebService attributes provide the following attributes:
Description-the value of this attribute contains a descriptive message, which is generated in the XML Web services Description file (such as the service Description and service help page) and displayed to potential users of XML Web services.
Name-the value of this attribute contains the Name of XML Web services. By default, this value is the name of the class that implements XML Web services. The Name attribute identifies the local part of the XML qualified Name of XML Web services. The Name attribute is also used to display the Name of XML Web services on the service help page.
Namespace-the value of this attribute contains the default Namespace of XML Web services. The XML namespace provides a method to create a name in an XML document. The name can be identified by a uniform resource identifier (URI. You can use an XML namespace to uniquely identify elements or attributes in an XML document. Therefore, in the service description of XML Web services, Namespace is used as the default Namespace for XML elements directly related to XML Web services. Use the default namespace http://tempuri.org/

Public class sample2: System. Web. Services. WebService
Sample2 inherits from the base class System. Web. Services. WebService. It provides the permission to directly access common ASP. NET objects (such as applications and session State objects. Note that the class must be public and there must be a public default constructor (a constructor without parameters ).

[WebMethod]
You can specify the methods available in XML Web services by placing the WebMethod Attribute before the Public method declaration. Private methods cannot serve as the entry points for XML Web services, although they can use the same classes and XML Web services Code can call them. The WebMethod attribute must be applied to each public method that can be used as part of XML Web services.

3. Name the above cs file sample2.asmx. cs, use csc/t: library $ File $ to compile it into sample2.asmx. dll, create a sub-directory bin under the virtual directory http: // localhost/ws/, and set sample2.asmx. dll copy to http: // localhost/ws/bin/
Now you can test your ws in the browser: http: // localhost/ws/sample2.asmx
Or http: // localhost/ws/sample2.asmx? Wsdl

Let's call this ws in flash (now it only contains one method GetUserName ).
1. Drag the WebSessionClasses component to the stage, import the Web service package to Fla, and delete the instances of the WebSessionClasses component on the stage.
2. Drag a Button component to the stage and name it GetUN_bt. Set the label attribute to "GetUserName ";
3. Add the following Action Script:
/**
ActionScript Class File -- Created with SAPIEN Technologies PrimalScript 3.0

@ Class wsSample_2
@ Package wsSample_2.as
@ Author JimLee
@ Codehint
@ Example
@ Tooltip
*/

Import mx. services .*;

Var myws: WebService = new WebService ("http: // localhost/ws/sample2.asmx? Wsdl ");

Function GetUserName (result ){
Trace ("ws returned value :");
Trace ("///////////////////////////");
Trace (result );
}

This. GetUN_bt.onPress = function (){
Var op_1: PendingCall = myws. GetUserName ("Joe !! ");
Op_1.onResult = GetUserName;
}

Hehe, no new things at all, but added the parameter value "Joe" to the PendingCall callback method !! "It's as good as using a local method!

Next, you can test it again.

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.