• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Flex(FlashBuilder)消费asp.netWebService

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Service1.asmx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace TestWebServiceForFlex
{
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [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,中国";
        }

        [WebMethod]
        public double Calc(double radius)
        {
            double d= radius * radius * Math.PI;
            return d;
        }
    }
}

前台Flex调用:

_Super_Service1.as

/**
 * This is a generated class and is not intended for modfication.  To customize behavior
 * of this service wrapper you may modify the generated sub-class of this class - Service1.as.
 */
package services.service1
{
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;

[ExcludeClass]
internal class _Super_Service1 extends com.adobe.fiber.services.wrapper.WebServiceWrapper
{
     
    // Constructor
    public function _Super_Service1()
    {
        // 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, "Calc");
		 operation.resultType = Number; 		 
        operations["Calc"] = 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 = "Service1";
        _serviceControl.port = "Service1Soap";
        wsdl = "http://localhost:3856/Service1.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 'Calc' 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 Calc(radius:Number) : mx.rpc.AsyncToken
	{
		model_internal::loadWSDLIfNecessary();
		var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("Calc");
		var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(radius) ;

		return _internal_token;
	}   
	 
}

}

界面文件:

TestWebServiceAspNet.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" width="797" height="512" xmlns:service1="services.service1.*">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			
			protected function btnGetResult_clickHandler(event:MouseEvent):void
			{
				CalcResult.token = service1.Calc(parseFloat( this.txtRadius.text));				
			}
			
			
			protected function button_clickHandler(event:MouseEvent):void
			{
				HelloWorldResult.token = service1.HelloWorld();
			}
			
		]]>
	</fx:Script>
	<fx:Declarations>		
		<service1:Service1 />
		<s:CallResponder />
		<s:CallResponder />
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Panel x="20" y="24" width="331" height="203" title="计算圆的面积">
		<s:Button x="69" y="99" label="计算" />
		<s:TextInput x="69" y="25" />
		<s:Label x="34" y="25" text="半径:"/>
		<s:Label x="36" y="69" text="结果:"/>
		<s:Label x="71" y="69" />
	</s:Panel>
	<s:Panel x="375" y="24" width="300" height="203" title="SayHello">
		<s:Button x="117" y="102" label="按钮" />
		<s:Label x="94" y="63" text="{HelloWorldResult.lastResult}"/>
	</s:Panel>
</s:Application>


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
【转载】2012年七个免费ASP空间分享-支持ASP、ASP.NET的空间发布时间:2022-07-10
下一篇:
asp.netc#lock有关发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap