Flex与webservice 通信DEMO

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
fontSize="12">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

private function loginClick():void
{
sendCount();
}

private function sendCount():void
{
UserWebservice.addEventListener(ResultEvent.RESULT, showResult);
UserWebservice.addEventListener(FaultEvent.FAULT, faultResult);
UserWebservice.GetStringTest.send();
}

private function showResult(event:ResultEvent):void
{
var rsStr:String=new String(event.result);
btLogin.label=rsStr;
txtUserID.text=rsStr;
textStr.text+=rsStr;
}

private function faultResult(faultmessage:FaultEvent):void
{
var faultStr:String=new String(faultmessage.message);
                 Alert.show(faultStr,"Fault Message");
textStr.text=faultStr;
}
]]>
</mx:Script>

<mx:WebService id="UserWebservice"
  wsdl="http://localhost/webData/Service1.asmx?wsdl"
  useProxy="false">
<mx:operation name="GetStringTest">
</mx:operation>
<!--<mx:operation name="UserLogin">
<mx:request>
<strUserID>{txtUserID.text}</strUserID>
<strUserPwd>{txtUserPwd.text}</strUserPwd>
</mx:request>
</mx:operation>-->
</mx:WebService>

<mx:Panel x="60"
 y="96"
 width="312"
 height="214"
 layout="absolute"
 title="用户登录">
<mx:Label x="23"
 y="29"
 text="登录用户"/>
<mx:Label x="23"
 y="68"
 text="登录密码"/>
<mx:TextInput x="92"
 y="27"
 id="txtUserID"/>
<mx:TextInput x="92"
 y="66"
 displayAsPassword="true"
 id="txtUserPwd"/>
<mx:Button x="92"
  y="128"
  label="登 录"
  width="71"
  height="27"
  id="btLogin"
  click="loginClick()"/>
<mx:Button x="181"
  y="128"
  label="注 册"
  width="71"
  height="27"
  id="btRegister"/>
<mx:HRule x="23"
 y="107"
 width="250"
 height="3"
 strokeColor="#990099"/>
<mx:Image x="34"
 y="118"
  source="images/Lang.png" width="48" height="48"/>
</mx:Panel>
<mx:TextArea id="textStr"
x="464"
y="96"
width="237"
height="231"/>

</mx:Application>

posted @ 2009-05-21 13:15  chinachen  阅读(634)  评论(2)    收藏  举报