One of my friend ask me about how to access multiple methods of a web Service.
I have created a web service which is having 4 methods. Three of them are just returning
a text String. While there is method ‘Login’ which accepts two arguments both of string
type and returns two diffent of text messages depending upon the argument passed. If u
Pass “Admin” as first argument and also “Admin” as the second argument then it returns
“Login Success” otherwise “Loging Failed”.
Here is the code of the webservice as well as the flex implementation of it.
Hope it will help you.
WebService
************************************************************
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
}
private string userid=“”;
private string pwd=“”;
private string loginResult = “”;
[WebMethod]
public string Login(string _userid ,string _pwd)
{
this.userid =_userid;
this.pwd = _pwd;
if ((_userid == “Admin” )&&(_pwd == “Admin”))
{
loginResult = “Loging Success”;
}
else
{
loginResult = “Loging Failed”;
}
return loginResult;
}
[WebMethod]
public string HelloWorld() {
return “Hello World”;
}
[WebMethod]
public string HiWorld()
{
return “Hi World”;
}
[WebMethod]
public string BiWorld()
{
return “Bi World”;
}
}
**********************************************************************
Flex Application MXML
***********************************************************************
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute“
xmlns:myService=”generated.webservices.*“>
<myService:Service id=”myService“>
</myService:Service>
<mx:HBox width=”100%” height=”100%” horizontalAlign=”center“>
<mx:VBox width=”300” height=”300” horizontalAlign=”center“>
<mx:Button id=”myButton” label=”Call hiWorld Method Of WebService” click=”myService.hiWorld()” />
<mx:Label id=”l1” text=”{myService.hiWorld_lastResult}“/>
</mx:VBox>
<mx:VBox width=”300” height=”300” horizontalAlign=”center“>
<mx:Button id=”myButton1” label=”Call helloWorld Method Of WebService” click=”myService.helloWorld()” />
<mx:Label id=”l2” text=”{myService.helloWorld_lastResult}“/>
</mx:VBox>
<mx:VBox width=”300” height=”300” horizontalAlign=”center“>
<mx:Button id=”myButton2” label=”Call biWorld Method Of WebService” click=”myService.biWorld()” />
<mx:Label id=”l3” text=”{myService.biWorld_lastResult}“/>
</mx:VBox>
<mx:VBox width=”300” height=”300” horizontalAlign=”center“>
<mx:Button id=”myButton3” label=”Call Login Method Of WebService” click=”myService.login(‘Admin’,‘Admin’)”/>
<mx:Label id=”l4” text=”{myService.login_lastResult}“/>
</mx:VBox>
</mx:HBox>
</mx:Application>
***********************************************************************
Enjoy Flexing………………











