加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex访问同一个webService的不同方法

发布时间:2020-12-15 05:04:36 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"? mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" mx:Style global{ fontSize:12pt; } /mx:Style mx:Script ![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert;
<?xml version="1.0" encoding="utf-8"?>  
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
                layout="absolute">  
    <mx:Style>  
  global{  
   fontSize:12pt;  
  }  
 </mx:Style>  
  
    <mx:Script>  
        <![CDATA[ 
            import mx.collections.ArrayCollection; 
            import mx.controls.Alert; 
            import mx.rpc.events.FaultEvent; 
            import mx.rpc.events.ResultEvent; 
 
            //引入远程调用的事件处理 
            //向WebService发送请求 
 
            private function hello():void 
            { 
                ws.sayHello.send(); 
            } 
            
            private function helloPerson():void 
            { 
                ws.sayHelloToPerson.send(); 
            }
            
 
            //显示hello()结果的处理函数 
            private function handleHelloResult(rs:ResultEvent):void 
            { 
                //得到返回的结果 
                var rsStr:String=rs.result.toString(); 
                txtHello.text=rsStr; 
            } 
            
             //显示helloPerson()结果的处理函数 
            private function handleHelloPersonResult(rs:ResultEvent):void 
            { 
                //得到返回的结果 
                var rsStr:String=rs.result.toString(); 
                txtHelloPerson.text=rsStr; 
            }
 
            private function faultResult(faultmessage:FaultEvent):void 
            { 
                var faultStr:String=new String(faultmessage.message); 
                Alert.show(faultStr,"WebService访问错误"); 
            } 
 
 
        ]]>  
    </mx:Script>  
    <mx:WebService id="ws"  
                   wsdl="http://localhost:6080/testWebService/services/HelloServices?wsdl"  
                   useProxy="false"  
                   showBusyCursor="true"  
                   fault="faultResult(event)">  
  
         <mx:operation name="sayHello" resultFormat="object" result="handleHelloResult(event)"/>
         <mx:operation name="sayHelloToPerson" resultFormat="object" result="handleHelloPersonResult(event)">
         	<mx:request>
         		<name>
         		{userName.text}	
         		</name>
         	</mx:request>
         </mx:operation>
    </mx:WebService>  
  
    <mx:Panel x="180"  
              y="78"  
              width="579"  
              height="272"  
              layout="absolute"  
              title="问候"  
              horizontalAlign="center"  
              verticalAlign="middle">  
        <mx:Button x="10"  
                   y="182"  
                   label="SayHello()"  
                   click="hello()"/>  
        <mx:Label x="10" y="21" text="结果:"/>
        <mx:Label x="17" y="91" id="txtHello"/>
        <mx:Button x="292"  
                   y="182"  
                   id="clear"  
                   click="helloPerson()" label="SayHelloToPerson()"/>
        <mx:Label x="292" y="103" text="结果:"/>
        <mx:Label x="366" y="103" id="txtHelloPerson"/>
        <mx:TextInput id="userName" x="366" y="19"/>
        <mx:Label x="292" y="21" text="输入姓名:"/>
    </mx:Panel>  
</mx:Application>  

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读