使用Flex访问ASP.net写的WebService .
来源:互联网 发布:yurisa的容貌知乎 编辑:程序博客网 时间:2024/05/16 07:43
使用Flex程序作为客户端访问用ASP.net写的Web服务的过程如下:
1。使用VS新建一个ASP.net Webservice Website,假设命名为Website9。编写一个HelloWorld方法,接受一个string类型的输入和一个string类型的输出。以下是这个WebService的源代码:
2。为这个WebSite项目指定一个固定端口,假设为8888。运行WebSite9可以看到这个WebService的WSDL地址为: http://localhost:8888/WebSite9/Service.asmx?WSDL
打开这个地址找到以下信息,代表了HelloWorld函数接受的输入参数名为input,返回的参数名为HelloWorldResult。
3。编写一个Flex程序以访问以上的WebService。以下通过两种方式:使用mxml和使用ActionScript。
方法一:使用mxml
方法二:使用ActionScript
1。使用VS新建一个ASP.net Webservice Website,假设命名为Website9。编写一个HelloWorld方法,接受一个string类型的输入和一个string类型的输出。以下是这个WebService的源代码:
- using System;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- using System.Xml.Linq;
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- // [System.Web.Script.Services.ScriptService]
- public class Service : System.Web.Services.WebService
- {
- public Service () {
- //Uncomment the following line if using designed components
- //InitializeComponent();
- }
- [WebMethod]
- public string HelloWorld(string input) {
- return "Hello World,"+input;
- }
- }
打开这个地址找到以下信息,代表了HelloWorld函数接受的输入参数名为input,返回的参数名为HelloWorldResult。
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
- <s:element minOccurs="0" maxOccurs="1" name="input" type="s:string" />
- </s:sequence>
- </s:complexType>
- </s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
- <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
- </s:sequence>
- </s:complexType>
- </s:element>
3。编写一个Flex程序以访问以上的WebService。以下通过两种方式:使用mxml和使用ActionScript。
方法一:使用mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12">
- <mx:Script>
- <![CDATA[
- import mx.rpc.events.ResultEvent;
- import mx.rpc.events.FaultEvent;
- private var ws:WebService=new WebService();
- internal function sendMessage():void{
- loader.HelloWorld.send();
- }
- internal function completeHandler(evt:ResultEvent):void{
- result_txt.text=evt.result.toString();
- }
- internal function errorHandler(evt:FaultEvent):void{
- result_txt.text=evt.fault.toString();
- }
- ]]>
- </mx:Script>
- <mx:WebService id="loader" wsdl="http://localhost:8888/WebSite9/Service.asmx?wsdl" result="completeHandler(event)" showBusyCursor="true" fault="errorHandler(event)">
- <mx:operation name="HelloWorld">
- <mx:request>
- <input> <!--输入参数的名字:input-->
- {input_txt.text}
- </input>
- </mx:request>
- </mx:operation>
- </mx:WebService>
- <mx:TextInput x="110" y="134" width="249" id="input_txt"/>
- <mx:Button x="376" y="134" label="发送请求" id="send_btn" click="sendMessage()"/>
- <mx:TextArea x="110" y="193" width="344" height="258" id="result_txt"/>
- </mx:Application>
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12">
- <mx:Script>
- <![CDATA[
- import mx.rpc.events.ResultEvent;
- import mx.rpc.events.FaultEvent;
- import mx.rpc.soap.WebService; //添加对WebService控件的引用
- private var ws:WebService=new WebService();
- internal function sendMessage():void{
- loader.HelloWorld.send();
- ws.HelloWorld.addEventListener("result",completeHandler);
- ws.HelloWorld.addEventListener("fault",errorHandler);
- ws.loadWSDL("http://localhost:8888/WebSite9/Service.asmx?WSDL");
- var str:String=input_txt.text;
- ws.HelloWorld(str); //直接调用远程函数
- }
- internal function completeHandler(evt:ResultEvent):void{
- result_txt.text=evt.result.toString();
- }
- internal function errorHandler(evt:FaultEvent):void{
- result_txt.text=evt.fault.toString();
- }
- ]]>
- </mx:Script>
- </mx:WebService>
- <mx:TextInput x="110" y="134" width="249" id="input_txt"/>
- <mx:Button x="376" y="134" label="发送请求" id="send_btn" click="sendMessage()"/>
- <mx:TextArea x="110" y="193" width="344" height="258" id="result_txt"/>
- </mx:Application>
- 使用Flex访问ASP.net写的WebService .
- Flex与asp.net的WebService通讯
- Flex与asp.net的WebService通讯
- Android 访问 .net C#写的webservice
- asp.net调用java写的webservice
- flex 与 .net 交互【基于WebService的数据访问】
- Flex与.NET互操作 基于WebService的数据访问
- Flex asp.net通过webservice通信
- javascript 利用xmlhttp访问asp.net 2.0 的webservice
- ASP.NET MVC中使用ASP.NET AJAX异步访问WebService
- 在W7部署WebService,报错“C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files”的写访问权限”
- ASP.NET WebService 使用Session
- flex访问同一个webService的不同方法
- Flex与.NET互操作(二):基于WebService的数据访问(上)
- Flex与.NET互操作(三):基于WebService的数据访问(下)
- Flex与.NET互操作(二) 基于WebService的数据访问(上)
- Flex与.NET互操作(三) 基于WebService的数据访问(下)
- .NET 访问JAVA的WebService使用SOAP头
- BIT-MAP的简单实现
- HTML速成
- 杭电4530-小Q系列故事——大笨钟
- Linux下的minicom和dnw
- PLSM场景管理器的使用
- 使用Flex访问ASP.net写的WebService .
- hdu 2709 Sumsets
- 64位操作系统下使用YUM下只安装纯净64位软件包的设定
- VS2010版快捷键
- linux su和sudo命令的区别
- 【待字闺中-2】单链表和之恋
- Flex 向ArrayCollection中添加数据,存在删掉,添加新值
- 【题解】【2013.8.1】pogodak←2013.8.1日作业
- IOS开发之多线程——NSInvocationOperation