flex中调用webservice的两种方法

1,用C#写好一个webservice,包含两个方法

    [WebMethod]
    public string HelloWorld()
   {
        return "Hello World";
    }

    [WebMethod]
    public int GetSum(int a,int b)
    {
        int c = 0;
        c = a + b;
        return c;
    }

2,通过mxml配置,调用

	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<s:WebService id="myWebService" wsdl="http://localhost:4358/WebServicetest/WebService.asmx?wsdl">
				<s:operation name="GetSum" resultFormat="object" result="myresultTwo(event)"/>
				<s:operation name="HelloWorld" resultFormat="object" result="myresultTwo(event)"/>
		</s:WebService>
	</fx:Declarations>
	<s:Button id="myOne" x="184" y="177" width="131" height="47" label="Methodone"
			  click="myOne_clickHandler(event)"/>
	<s:Button id="myTwo" x="393" y="177" width="131" height="47" label="MethodTwo"
			  click="myTwo_clickHandler(event)"/>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.rpc.events.ResultEvent;
			import mx.rpc.soap.WebService;
			
			public function myresultOne(event:ResultEvent):void
			{
				Alert.show(event.result.toString());
			}
			public function myresultTwo(event:ResultEvent):void
			{
				Alert.show(event.result.toString());
			}

			protected function myOne_clickHandler(event:MouseEvent):void
			{
				// Todo Auto-generated method stub
				myWebService.HelloWorld();
			}
			
			protected function myTwo_clickHandler(event:MouseEvent):void
			{
				// Todo Auto-generated method stub
				myWebService.GetSum(7,9);
				
			}
			
		]]>
	</fx:Script>

3,通过AS调用

			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				// Todo Auto-generated method stub
				var myser:WebService=new WebService();
				myser.wsdl="http://localhost:4358/WebServicetest/WebService.asmx?wsdl";
				myser.loadWSDL();
				myser.getoperation("HelloWorld").addEventListener(ResultEvent.RESULT,myresultOne);
				myser.getoperation("HelloWorld").send();
				myser.getoperation("GetSum").addEventListener(ResultEvent.RESULT,myresultTwo);
				myser.getoperation("GetSum").send(2,3);	
			}
			
			public function myresultOne(event:ResultEvent):void
			{
				Alert.show(event.result.toString());
			}
			public function myresultTwo(event:ResultEvent):void
			{
				Alert.show(event.result.toString());
			}

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...