Flex 调用WebService1(基于.net)

   以.net平台下C#语言开发的WebService为web服务,使用flex  actionscript语句访问webservice接口 

Flex:  Temp.mxml部分代码

//调用WebService
			import mx.controls.Alert;  
			import mx.rpc.events.ResultEvent;
			import mx.rpc.soap.WebService;  
			
			protected function getWebService():void  
			{  
				//Security.allowDomain("*");
				//Security.allowInsecureDomain("*");
				//Security.loadPolicyFile("http://localhost/crossdomain.xml");
				var ws :mx.rpc.soap.WebService = new mx.rpc.soap.WebService();  
				ws.wsdl= "http://localhost/XXX/MyWebService.asmx?WSDL";  
				ws.addEventListener(ResultEvent.RESULT,resultFunction);//增加返回结果的监听
				ws.getOperation("HelloWorld").send();
				//ws.getOperation("Sum").send("3","5"); //传递参数
				ws.loadWSDL();  
			}  
			
			private function resultFunction(event:ResultEvent){ 
				var s:String =event.result as String;
				Alert.show(s.toString());  
			} 

   其中wsdl属性指定到要访问的WebService的wsdl地址。

添加Flex的控件   

<s:HGroup width="100%" verticalAlign="middle">
			
			<mx:Text id="resultweb"/>
			<common:Cbutton id="btn_call" label="调用webService" click="getWebService()"/>
		</s:HGroup>

  其中WebService接口见  [WebService调用1(.Net)http://www.cnblogs.com/ashleyboy/p/3657604.html]

 

posted @ 2014-04-14 14:15  互联网荒漠  阅读(286)  评论(0编辑  收藏  举报