现在的位置: 首页 > 综合 > 正文

在Flash中调用WS时的身份验证_6:客户端

2012年03月01日 ⁄ 综合 ⁄ 共 2157字 ⁄ 字号 评论关闭
面讲了WS端,下面在客户端调用,如下所示:
  

    调用方法和普通客户端调用WS没有什么不同——Flash Player SOAP Web 服务的下层网络传送始终是 HTTP POST,不需要客户端为身份验证撰写任何特殊的代码。因此,可以应用在 Flash HTTP 传送层上的任何安全性方式(例如 SSL)通过 Flash 中的 Web 服务调用获得支持。SSL/HTTPS 为 SOAP 消息传递提供最常用的传送安全性方式,而在传送层与 SSL 结合使用 HTTP BASIC 身份验证是当今最常用的 Web 站点安全性方式。
   下面是代码:
  ///  #include "login.as"

import mx.controls.*;
import mx.services.*;
import mx.transitions.*;
import mx.transitions.easing.*;

stop();

var myws:WebService=new WebService("http://localhost/claw/login.asmx?wsdl");

this.onLoad=function(){
    var t:Tween=new Tween(this,"_alpha",Strong.easeIn,0,100,24);
    this.rjyzm_txt.text=Math.round(Math.random()*8999+1000);
    }

this.ok_bt.onPress=function(){
    var tmc:MovieClip=this._parent;
    var t:Boolean=false;
    t=t||tmc.name_txt.text=="";
    t=t||tmc.pw_txt.text=="";
    t=t||tmc.yzm_txt.text=="";
    if (t){
        Alert.show("用户名称、用户密码或者验证码不能为空值,请检查后重新输入!!","..::  重要提示  ::..",0,tmc,empty,"icon_1",empty);
        }else{
            if (tmc.yzm_txt.text<>tmc.rjyzm_txt.text){
                Alert.show("验证码输入有误,请检查后重新输入!!","..::  重要提示  ::..",0,tmc,empty,"icon_1",empty);
                }else{
                    //在此调用ws检查用户输入
                    var op_1:PendingCall=myws.checkUser(tmc.name_txt.text,tmc.pw_txt.text);
                    op_1.onResult=t_login;
                    }
            
            }
    
    }
    
this.cancel_bt.onPress=function(){
    var tmc:MovieClip=this._parent;    
    
    tmc.rjyzm_txt.text=Math.round(Math.random()*8999+1000);
    tmc.pw_txt.text="";
    tmc.yzm_txt.text="";
    tmc.name_txt.text="";
    }
    
function t_login(result){
    //trace(result);
    if (result==true){
        _root.play();
        }else{
            Alert.show("用户无法登陆,请重试!!","..::  重要提示  ::..",0,tmc,empty,"icon_1",empty);
        }
    }

   ////#include "Test.as"
import mx.services.*;

stop();

var myws:WebService=new WebService("http://localhost/claw/admin/admin.asmx?wsdl");

function test(result){
    //trace(result);
    _root.test_txt.text=result;
    }
    
this.wsTest_bt.onPress=function(){
    var op_1:PendingCall=myws.test();
    op_1.onResult=test;
    }

   上面这个例子写的很简单,只是希望通过它来阐述一下asp.net下WS和flash交互中怎样处理用户的验证和授权的最基本的过程,当然,根据实际需要,你的代码可能要比这复杂的多。

抱歉!评论已关闭.