获取网络发布的webservice
GetMonths.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
private var startTime:int;
private var endTime:int;
private var endTime:int;
private function button_click():void {
webService.getMonths.send();
startTime = getTimer();
lbl.text = "";
}
webService.getMonths.send();
startTime = getTimer();
lbl.text = "";
}
private function getMonths_result(evt:ResultEvent):void {
textArea.text = ObjectUtil.toString(evt.result);
calcTime();
}
textArea.text = ObjectUtil.toString(evt.result);
calcTime();
}
private function getMonths_fault(evt:FaultEvent):void {
Alert.show(evt.type);
calcTime();
}
Alert.show(evt.type);
calcTime();
}
private function calcTime():void {
endTime = getTimer();
lbl.text = "total time: " + (endTime - startTime) + "ms";
}
]]>
</mx:Script>
endTime = getTimer();
lbl.text = "total time: " + (endTime - startTime) + "ms";
}
]]>
</mx:Script>
<mx:WebService id="webService"
wsdl=" http://www.flash-mx.com/ws/months.cfc?wsdl">
<mx:operation name="getMonths"
resultFormat="object"
result="getMonths_result(event);"
fault="getMonths_fault(event);" />
</mx:WebService>
wsdl=" http://www.flash-mx.com/ws/months.cfc?wsdl">
<mx:operation name="getMonths"
resultFormat="object"
result="getMonths_result(event);"
fault="getMonths_fault(event);" />
</mx:WebService>
<mx:ApplicationControlBar dock="true">
<mx:Button id="button"
label="get months from web service"
click="button_click();" />
<mx:Spacer width="100%" />
<mx:Label id="lbl" />
</mx:ApplicationControlBar>
<mx:Button id="button"
label="get months from web service"
click="button_click();" />
<mx:Spacer width="100%" />
<mx:Label id="lbl" />
</mx:ApplicationControlBar>
<mx:TextArea id="textArea"
editable="false"
width="100%"
height="100%" />
editable="false"
width="100%"
height="100%" />
</mx:Application>
=================================================================
使用自己发布的WebService与Flex通信
<?xml version="1.0" encoding="UTF-8" ?>
-
<
wsdl:definitions targetNamespace
="
http://service.jy.com
"
xmlns:soapenc12
="
http://www.w3.org/2003/05/soap-encoding
"
xmlns:tns
="
http://service.jy.com
"
xmlns:wsdl
="
http://schemas.xmlsoap.org/wsdl/
"
xmlns:xsd
="
http://www.w3.org/2001/XMLSchema
"
xmlns:soap11
="
http://schemas.xmlsoap.org/soap/envelope/
"
xmlns:wsdlsoap
="
http://schemas.xmlsoap.org/wsdl/soap/
"
xmlns:soapenc11
="
http://schemas.xmlsoap.org/soap/encoding/
"
xmlns:soap12
="
http://www.w3.org/2003/05/soap-envelope
">
<
wsdl:part
name
="
parameters
"
element
="
tns:getKeyResponse
" />
</
wsdl:message
>
<
wsdl:part
name
="
parameters
"
element
="
tns:getKey
" />
</
wsdl:message
>
<
wsdl:part
name
="
parameters
"
element
="
tns:loginResponse
" />
</
wsdl:message
>
<
wsdl:part
name
="
parameters
"
element
="
tns:login
" />
</
wsdl:message
>
<
wsdl:input
name
="
getKeyRequest
"
message
="
tns:getKeyRequest
" />
<
wsdl:output
name
="
getKeyResponse
"
message
="
tns:getKeyResponse
" />
</
wsdl:operation
>
<
wsdl:input
name
="
loginRequest
"
message
="
tns:loginRequest
" />
<
wsdl:output
name
="
loginResponse
"
message
="
tns:loginResponse
" />
</
wsdl:operation
>
</
wsdl:portType
>
<
wsdlsoap:binding
style
="
document
"
transport
="
http://schemas.xmlsoap.org/soap/http
" />
</
wsdl:binding
>
<
wsdlsoap:address
location
="
http://localhost:8081/xfireservice/service/UserService
" />
</
wsdl:port
>
</
wsdl:service
>
</
wsdl:definitions
>
===============================================================================
GetKeyFromXFire.mxml
<?xml version="1.0" encoding="utf-8"?>
<!-- 从WSDL为http://localhost:8081/xfireservice/service/UserService?wsdl的webservice执行getKey()操作 -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
private var startTime:int;
private var endTime:int;
private var endTime:int;
private function button_click():void {
//执行webservice的getKey(String in0,String in1)操作
webService.getKey('fisher','123456');
startTime = getTimer();
lbl.text = "";
}
//执行webservice的getKey(String in0,String in1)操作
webService.getKey('fisher','123456');
startTime = getTimer();
lbl.text = "";
}
private function getKeys_result(evt:ResultEvent):void {
//将getKey(String in0,String in1)结果赋予textArea
textArea.text = ObjectUtil.toString(evt.result);
calcTime();
}
//将getKey(String in0,String in1)结果赋予textArea
textArea.text = ObjectUtil.toString(evt.result);
calcTime();
}
private function getKeys_fault(evt:FaultEvent):void {
Alert.show(evt.type);
calcTime();
}
Alert.show(evt.type);
calcTime();
}
private function calcTime():void {
endTime = getTimer();
lbl.text = "total time: " + (endTime - startTime) + "ms";
}
]]>
</mx:Script>
endTime = getTimer();
lbl.text = "total time: " + (endTime - startTime) + "ms";
}
]]>
</mx:Script>
<!-- 获取webservice -->
<mx:WebService id="webService"
wsdl="http://localhost:8081/xfireservice/service/UserService?wsdl">
<!-- 获取webservice的操作函数 -->
<mx:operation name="getKey"
resultFormat="object"
result="getKeys_result(event);"
fault="getKeys_fault(event);" />
</mx:WebService>
<mx:WebService id="webService"
wsdl="http://localhost:8081/xfireservice/service/UserService?wsdl">
<!-- 获取webservice的操作函数 -->
<mx:operation name="getKey"
resultFormat="object"
result="getKeys_result(event);"
fault="getKeys_fault(event);" />
</mx:WebService>
<mx:ApplicationControlBar dock="true">
<mx:Button id="button"
label="get key from web service"
click="button_click();" />
<mx:Spacer width="100%" />
<mx:Label id="lbl" />
</mx:ApplicationControlBar>
<mx:Button id="button"
label="get key from web service"
click="button_click();" />
<mx:Spacer width="100%" />
<mx:Label id="lbl" />
</mx:ApplicationControlBar>
<mx:TextArea id="textArea"
editable="false"
width="100%"
height="100%" />
editable="false"
width="100%"
height="100%" />
</mx:Application>
====================================================================
FlexWebService.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
<mx:WebService id="ws" wsdl=" http://localhost:8080/ws/services/wjhService?wsdl" useProxy="false" showBusyCursor="true"> <mx:operation name="put" result="Alert.show('恭喜!添加成功','返回框',3)" fault="Alert.show('添加失败','失败',3)"> </mx:operation> <mx:operation name="get" result="showInfo(event)" fault="Alert.show('失败','tile',2)"> </mx:operation> </mx:WebService> <mx:XML> </mx:XML> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.controls.Alert; private var com:String ; private var cio:String ; public function addCompany():void { com = company.text ; cio = ceo.text ; ws.put(com,cio); } public function seeCeo():void { var str:String; str = company.text; ws.get(str); } public function showInfo(event:ResultEvent):void { var str:String; str = event.result.toString(); Alert.show(str,"凯旋",2); } ]]> </mx:Script> <mx:Panel title="DataGrid Control Example" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10"> <mx:Label x="10" y="10" text="公司" height="39" width="55" fontSize="21" fontWeight="bold"/> <mx:TextInput x="61" y="10" height="31" id="company"/> <mx:Label x="10" y="66" text="老大" width="55" height="49" fontSize="21" fontWeight="bold"/> <mx:TextInput x="61" y="75" height="31" id="ceo"/> <mx:Button label="添加" height="37" fontSize="17" id="add" click="addCompany();"/> <mx:Button label="查看" height="29" fontSize="17" id="see" click="seeCeo();"/> </mx:Panel> </mx:Application>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
<mx:WebService id="ws" wsdl=" http://localhost:8080/ws/services/wjhService?wsdl" useProxy="false" showBusyCursor="true"> <mx:operation name="put" result="Alert.show('恭喜!添加成功','返回框',3)" fault="Alert.show('添加失败','失败',3)"> </mx:operation> <mx:operation name="get" result="showInfo(event)" fault="Alert.show('失败','tile',2)"> </mx:operation> </mx:WebService> <mx:XML> </mx:XML> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.controls.Alert; private var com:String ; private var cio:String ; public function addCompany():void { com = company.text ; cio = ceo.text ; ws.put(com,cio); } public function seeCeo():void { var str:String; str = company.text; ws.get(str); } public function showInfo(event:ResultEvent):void { var str:String; str = event.result.toString(); Alert.show(str,"凯旋",2); } ]]> </mx:Script> <mx:Panel title="DataGrid Control Example" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10"> <mx:Label x="10" y="10" text="公司" height="39" width="55" fontSize="21" fontWeight="bold"/> <mx:TextInput x="61" y="10" height="31" id="company"/> <mx:Label x="10" y="66" text="老大" width="55" height="49" fontSize="21" fontWeight="bold"/> <mx:TextInput x="61" y="75" height="31" id="ceo"/> <mx:Button label="添加" height="37" fontSize="17" id="add" click="addCompany();"/> <mx:Button label="查看" height="29" fontSize="17" id="see" click="seeCeo();"/> </mx:Panel> </mx:Application>