<mx:WebServiceid="dataService"
wsdl="http://localhost/FlashFlex/DataWebService.asmx?wsdl"
useProxy="false">
<mx:operationname="HelloWorld"result="onSuccess(event)"fault="onFault(event)"/>
<mx:operationname="GetBook"fault="onFault(event)"result="onObjectSuccess(event)"/>
</mx:WebService>
///<summary>
///返回字符串
///</summary>
///<returns></returns>
[WebMethod]
publicstringHelloWorld()
{
return"HelloWorld";
}
///<summary>
///返回一个简单对象
///</summary>
///<returns></returns>
[WebMethod]
publicBookGetBook()
{
returnnewBook
{
Id=1,
Name="三国演义",
Author="罗贯中",
Price=100
};
}
双击代码全选 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1<mx:Script> 2 <![CDATA[ 3 importmx.controls.Alert; 4 importmx.rpc.events.FaultEvent; 5 importmx.rpc.events.ResultEvent; 6 7 /** 8 *向WebService发起请求--调用HelloWorld方法,dataService为<mx:WebService>的id 9 **/ 10 internalfunctiononRequest():void 11 { 12 dataService.HelloWorld(); 13 } 14 15 /** 16 *请求成功处理返回结果 17 **/ 18 internalfunctiononSuccess(evt:ResultEvent):void 19 { 20 Alert.show(evt.result.toString()); 21 } 22 23 24 /** 25 *请求失败的处理函数 26 **/ 27 internalfunctiononFault(evt:FaultEvent):void 28 { 29 Alert.show("访问WebService失败!"); 30 } 31 ]]> 32</mx:Script> |
双击代码全选 | |
1 2 3 4 5 6 7 8 9 10 | 1 ///<summary> 2 ///将传递进来的参数转化为大写字符返回 3 ///</summary> 4 ///<paramname="value"></param> 5 ///<returns></returns> 6 [WebMethod] 7 publicstringConvertToUpper(stringvalue) 8 { 9 returnvalue.ToUpper(); 10 } |
双击代码全选 | |
1 2 3 4 5 6 7 8 9 10 | 1<mx:operationname="ConvertToUpper" result="onSuccess(event)"fault="onFault(event)"/> 1 /** 2 *向WebService发起请求 3 **/ 4 internalfunctiononRequest():void 5 { 6 //dataService.HelloWorld(); 7 dataService.ConvertToUpper("abcdefg"); 8 } |
双击代码全选 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 1 internalfunctiononObject():void 2 { 3 dataService.GetBook(); 4 } 5 6 internalfunctiononObjectSuccess(evt:ResultEvent):void 7 { 8 //直接通过事件的result属性得到返回值,然后直接访问属性便OK 9 Alert.show(evt.result.Name); 10 } 11 12 /** 13 *请求失败的处理函数 14 **/ 15 internalfunctiononFault(evt:FaultEvent):void 16 { 17 Alert.show("访问WebService失败!"); 18 } |
| 欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |