在我的RIA系统中,先后使用过Flourinfa、Weborb代理,后又使用HttpServicew与asp.net通信交互,但Flex的ArrayCollection类本身有点问题,不能实现特定的需要,所以采用vs2008 Webservice方式。先把我的测试代码贴出来
C#代码:
using System.Web;
using System.Web.Services;
namespace AvFashionWebService
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://192.168.1.188/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
flex调用代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function onResult(event:ResultEvent):void
{
Alert.show("called");
output.text="返回结果:"+event.result;
}
private function onFault( event:FaultEvent) : void
{
output.text ="调用失败:" +event.fault.message.toString();
}
private function ServiceCall():void
{
Alert.show("call");
service.HelloWorld();
}
]]>
</mx:Script>
<mx:WebService
id="service"
wsdl="http://192.168.1.188/test/Service1.asmx?WSDL"
showBusyCursor="true"
useProxy="false">
<mx:operation name="HelloWorld" result="onResult(event)" fault="onFault(event)"/>
</mx:WebService>
<mx:Button x="388" y="124" label="Call Webservice" height="44" fontSize="12" click="ServiceCall()"/>
<mx:TextArea x="10" y="124" width="358" id="output"/>
</mx:Application>