Home > ASP.NET, C#, Flex > Invoke a ASP.NET WebService from Flex

Invoke a ASP.NET WebService from Flex

Here, I used a basic WebService created with ASP.NET. Below is a basic hello world functionality we get when creating a new WebService with Visual Studio.

using System.Web.Services;
 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 
public class Service : System.Web.Services.WebService
{
    public Service () {
 
    }
 
    [WebMethod]
    public string HelloWorld() {
        return "Hello World - This is Praveen";
    }
}

Below is the basic mxml code which will show you text from WebService:

image

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
<mx:Script>
	<![CDATA[
		import mx.controls.Alert;
		import mx.rpc.events.FaultEvent;
		import mx.rpc.events.ResultEvent;
		private function result(event:ResultEvent):void {
			Alert.show(event.result.toString());
		}
		private function fault(event:FaultEvent):void {
			Alert.show(event.toString());
		}
		private function invokemethod(event:MouseEvent):void {
			ws.HelloWorld();
		}
	]]>
</mx:Script>
 
<mx:WebService id="ws" wsdl="http://localhost/FlexWSTest/Service.asmx?WSDL">
<mx:operation 
	name="HelloWorld" 
	resultFormat="object"
	result="result(event)"
	fault="fault(event)"
	 />
</mx:WebService>		
	<mx:Button x="236" y="177" label="Button" click="invokemethod(event)" />
</mx:Application>
VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)

No related posts.

Categories: ASP.NET, C#, Flex