zoukankan      html  css  js  c++  java
  • flex连接WebService简单例子

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 
    (C) aisajiajiao 2011
    Flex调用WebService
    -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    	
    	<mx:Script>
    		<![CDATA[
    			
    			import mx.rpc.events.ResultEvent;
    			import mx.rpc.events.FaultEvent;
    			import mx.rpc.soap.LoadEvent;
    			import mx.rpc.soap.WebService;
    			import mx.controls.Alert;
    			import mx.collections.ArrayCollection;
    			
    			//private var str:String = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
    			private var str:String = "http://fy.webxml.com.cn/webservices/EnglishChinese.asmx?wsdl";
    			private var webService:WebService;
    			[Bindable]
    			public var ss:ArrayCollection;
    			private function onClick():void
    			{
    				//创建并实例化WebService示例,不过之前要先导入WebService类
    				webService = new WebService();
    				webService.wsdl = str;
    				webService.loadWSDL(str);
    				//事件侦听我就不说了,文档上都有
    				webService.addEventListener(LoadEvent.LOAD, onLoad);
    				webService.addEventListener(ResultEvent.RESULT, onResult);
    				webService.addEventListener(FaultEvent.FAULT, onFault);
    				//webService。GetWeatherByZipCode.addEventListener(ResultEvent.RESULT, onResult);
    				//webService。GetWeatherByZipCode.addEventListener(FaultEvent.FAULT, onFault);
    			}
    			
    			private function onLoad(e:LoadEvent):void
    			{
    				//进行相关的操作
    				//webService.getWeatherbyCityName(txt.text.toString());
    				webService.TranslatorString(txt.text.toString());
    			}
    			
    			private function onResult(e:ResultEvent):void
    			{
    				ss=(e.result) as ArrayCollection;
    				for(var i:int=0;i<ss.length;i++){
    					myWeatherReport.text += ss[i]+"\n";
    				}
    				
    			}
    			
    			private function onFault(e:FaultEvent):void
    			{
    				trace(e.message);
    				Alert.show("错误:"+e.fault.faultString+"细节:"+e.fault.faultDetail,"错误");
    			}
    		]]>
    	</mx:Script>
    	
    	<mx:Button label="点击开始转换" click="onClick()" />
    	<mx:Text id="txt" text="hello" />
    	<mx:TextArea id="myWeatherReport" height="100%" width="80%" editable="false" />
    </mx:Application>
    

      要先看他的WSDL查看数据输入输出类型

  • 相关阅读:
    python | if else || where true 流程控制
    python |生成器
    python| 什么是迭代器?
    Python -WordCloud安装、词云制作
    技巧 |Python 使用dict.fromkeys()快速生成一个字典
    python 列表(list)去重方法总结
    区别 |python 的read、readline、readlines和write、writelines
    区别 |Python的 open() 和with open() as
    散点图和气泡图的几种制作方法
    宽表和窄表的建设该如何选择?
  • 原文地址:https://www.cnblogs.com/leonbond/p/2587530.html
Copyright © 2011-2022 走看看