flex 访问WebService的方法有很多种,使用FLEX4中的"数据/服务"功能可以自动生成访问WebService的代理类,这样可以避免把所有的数据访问都写到MXML页面上,便于重复利用,同时可以直接导入后台自定义数据类型,方便传参。

直接上代码:其中WebService接口

namespace MyNetWebService
{
/// <summary>
/// MyWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuriTemp.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class MyWebService : System.Web.Services.WebService
{ [WebMethod]
public string HelloWorld()
{
return "Hello World";
} [WebMethod]
public Model[] GetDetailResult(SearchParameter parmeter, Staff staff)
{
return ModelHelp.GetSaleDetailResult(parmeter, staff);
}
}
}

添加WebService服务:

连接数据/服务—>Web服务—>WSDL URL:  填写服务地址(http://localhost/XXX/MyWebService.asmx?WSDL)

使用FLEX4中的"数据/服务"功能 在services 下生成的代理类:

        

数据/服务 下 导入了webService的方法 和 自定义类型

自动生成访问WebService的代理类_Super_MyWebService.as

/**
* This is a generated class and is not intended for modification. To customize behavior
* of this service wrapper you may modify the generated sub-class of this class - MyWebService.as.
*/
package services.mywebservice
{
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.services.wrapper.WebServiceWrapper;
import com.adobe.serializers.utility.TypeUtility;
import mx.rpc.AbstractOperation;
import mx.rpc.AsyncToken;
import mx.rpc.soap.mxml.Operation;
import mx.rpc.soap.mxml.WebService;
import valueObjects.DetailSearchParameter;
import valueObjects.Employee;
import valueObjects.Sale; [ExcludeClass]
internal class _Super_MyWebService extends com.adobe.fiber.services.wrapper.WebServiceWrapper
{ // Constructor
public function _Super_MyWebService()
{
// initialize service control
_serviceControl = new mx.rpc.soap.mxml.WebService();
var operations:Object = new Object();
var operation:mx.rpc.soap.mxml.Operation; operation = new mx.rpc.soap.mxml.Operation(null, "HelloWorld");
operation.resultType = String;
operations["HelloWorld"] = operation; operation = new mx.rpc.soap.mxml.Operation(null, "GetDetailResult");
operation.resultElementType = valueObjects.Sale;
operations["GetDetailResult"] = operation; _serviceControl.operations = operations;
try
{
_serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
}
catch (e: Error)
{ /* Flex 3.4 and eralier does not support the convertResultHandler functionality. */ } _serviceControl.service = "MyWebService";
_serviceControl.port = "MyWebServiceSoap";
wsdl = "http://localhost/XXX/MyWebService.asmx?WSDL";
model_internal::loadWSDLIfNecessary(); model_internal::initialize();
} /**
* This method is a generated wrapper used to call the 'HelloWorld' operation. It returns an mx.rpc.AsyncToken whose
* result property will be populated with the result of the operation when the server response is received.
* To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value.
* You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
*
* @see mx.rpc.AsyncToken
* @see mx.rpc.CallResponder
*
* @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
*/
public function HelloWorld() : mx.rpc.AsyncToken
{
model_internal::loadWSDLIfNecessary();
var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("HelloWorld");
var _internal_token:mx.rpc.AsyncToken = _internal_operation.send() ; return _internal_token;
} /**
* This method is a generated wrapper used to call the 'GetDetailResult' operation. It returns an mx.rpc.AsyncToken whose
* result property will be populated with the result of the operation when the server response is received.
* To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value.
* You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
*
* @see mx.rpc.AsyncToken
* @see mx.rpc.CallResponder
*
* @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
*/
public function GetDetailResult(parmeter:valueObjects.DetailSearchParameter, loginEmp:valueObjects.Employee) : mx.rpc.AsyncToken
{
model_internal::loadWSDLIfNecessary();
var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("GetDetailResult");
var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(parmeter,loginEmp) ; return _internal_token;
} } }

 自动生成访问WebService的代理类MyWebService.as

/**
* This is a generated sub-class of _MyWebService.as and is intended for behavior
* customization. This class is only generated when there is no file already present
* at its target location. Thus custom behavior that you add here will survive regeneration
* of the super-class.
**/ package services.mywebservice
{ public class MyWebService extends _Super_MyWebService
{ } }

Flex 端Temp.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
layout="vertical" width="100%" height="100%"
xmlns:common="common.*"
xmlns:mywebservice="services.mywebservice.*"
>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.WebService;
import mx.controls.Alert; protected function btn_call_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
getresult.token=MyWebService.HelloWorld();
} protected function getresult_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
if(event.result!=null)
{
resultweb.text=event.result as String;
}
} ]]>
</fx:Script>
<!-- 引用css样式 -->
<fx:Style source="css/style.css" /> <fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<mywebservice:MyWebService id="MyWebService" showBusyCursor="true" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"/>
<s:CallResponder id="getresult" result="getresult_resultHandler(event)" />
</fx:Declarations>
<s:VGroup width="100%" height="100%" paddingLeft="" paddingRight="" paddingBottom="" paddingTop="">
<s:HGroup width="100%" verticalAlign="middle"> <mx:Text id="resultweb"/>
<common:Cbutton id="btn_call" label="调用webService" click="btn_call_clickHandler(event)" />
</s:HGroup>
<s:HGroup width="100%" verticalAlign="middle">
<s:Label verticalAlign="middle" styleName="msgTxtStyle" width="100%" id="msg_label"/>
</s:HGroup>
</s:VGroup>
</mx:Module >

运行结果:

flex 调用WebService2(基于.net)的更多相关文章

  1. flex 调用WebService1(基于.net)

    以.net平台下C#语言开发的WebService为web服务,使用flex  actionscript语句访问webservice接口 Flex:  Temp.mxml部分代码 //调用WebSer ...

  2. Flex调用java webservice

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  3. Flex 调用webService

    今天手头没事,就学习下 Flex 调用webService的方法.本地测试OK  和大家分享下. ——————————————————————————————————————————————————— ...

  4. Flex与Java交互(Flex调用java类展示数据)解析xml展示数据

    Flex与java通信最简单例子(详细说明了各种需要注意的配置):http://blog.csdn.net/u010011052/article/details/9116869 Flex与java通信 ...

  5. flex调用JS报安全沙箱错误解决办法

    flex调用JS方法弹窗时一般会报安全沙箱错误,只要将被调用的JS方法设置延时就可解决. function openKqQuery(){ window.showModalDialog("pa ...

  6. Flex调用JavaScript获取文件路径

    Flex的Web中有FileReference的类可以对文件操作,实现上传.下载的功能,但是没有办法获取到文件的路径. 普遍的方法是Flex调用JavaScript的文件浏览功能来获取文件路径. 1. ...

  7. flex 调用gp服务

    同步异步说明: gp服务分为同步和异步两种模式,两者的区别是:同步:适合于快速的处理,数据量较小,本质区别在于同步模式,服务器处理之后,处理结果并不在服务器端保存,而是将结果发送至客户端,由客户端去显 ...

  8. flex调用webservice中的datatable结果写入datagrid

    webservice配置文件 <appSettings> <add key="sqlConDuke" value="server=10.9.34.88; ...

  9. JAVA WEBSERVICE服务端&客户端的配置及调用(基于JDK)

    前言:我之前是从事C#开发的,因公司项目目前转战JAVA&ANDROID开发,由于对JAVA的各种不了解,遇到的也是重重困难.目前在做WEBSERVICE提供数据支持,看了网上相关大片的资料也 ...

随机推荐

  1. 使用.NET框架、Web service实现Android的文件上传(一)

    上面是上传结果的展示,下面具体讲一下实现过程. 一.Web Service (.NET) namespace VedioPlayerWebService.service.vedios { [WebSe ...

  2. Oracle instr 及 like

    原文: http://www.cnblogs.com/crazyjava/archive/2012/10/31/2748202.html instr(string1,string2[,start_po ...

  3. 洛谷 P1896 互不侵犯King

    P1896 [SCOI2005]互不侵犯King 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共 ...

  4. mapreduce的基本思想

    1.什么是mapreduce mapreduce是hadoop自带的分布式计算框架. 2.mapreduce的基本思想 2.1.能够解决什么问题假设一个场景:一个电商系统,统计某个手机号的用户的上行和 ...

  5. 在Ubuntu上安装VmTools

    1.添加VmTools 2.解压 .tag.gz文件 使用Linux命令: tar –zxvf src –c dis -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 ...

  6. SVN - 详细文档

    1.首先打开Cornerstone 2.然后如下图所示: 3.选择对应的仓库,如下图所示 4.然后Import完成之后,就把本地的文件提交到SVN服务器上了,如下图所示,另外如果你想要使用SVN进行版 ...

  7. Tomcat JVM

    https://www.mulesoft.com/tcat/tomcat-jvm https://www.mulesoft.com/tcat/tomcat-catalina https://www.m ...

  8. keil or c51 汇编调用c语言函数 容易忽视的问题

    最近,在用keil 写一个小程序时,想实践一下从汇编调用 C语言函数,我们都知道C语言调用汇编函数讨论得较多,但反过来,从汇编中调用C语言的函数未见深入分析:在开始的时候,还是忽视了一个问题,就是对现 ...

  9. QtCreator调试传入运行参数

    QtCreator是非常不错的IDE,最近在做的Qt命令行应用,因为调试的环境不同等问题,需要在调试的时候为 main() 传入参数.度娘了半天,没找到方法,只能自力更生.后来在“项目-构建和运行-运 ...

  10. 微软官方的Unity支持组件

    https://unity.codeplex.com/ http://www.nuget.org/packages/Unity.Interception/ http://www.nuget.org/p ...