The Flash code:
Code:
import mx.services.*;
/* import all of the webservices class packages.
Note: if you do not use the above import statement you will have to
call the web service with the full path (new mx.services.WebService(..) */
// set it up so that the service is called when the button is pressed.
result_btn.onPress = function() {
// Create a new instance of web service called - stockservice.
var stockservice = new WebService("http://rode-server/Webservices/helloworld/hello.asmx?WSDL");
// Call the doCompanyInfo method and assign it to the pending call object to handle results.
stockResultObj = stockservice.HelloWorld(txtname.text);
// the onResult function is called if the service is successful
stockResultObj.onResult = function(result) {
// example result values. The result is a decoded actionscript object
//version of the xml returned by the operation.
// In this case the result is a object with company, lastPrice etc being properties.
txthello.text = result.bla;
txthello2.text = result.bla2;
}
stockResultObj.onFault = function(fault) {
// If there is any error such as the service not working, the onFault handler will be invoked.
trace(fault.faultCode + "," + fault.faultstring);
}
}
After you created a webservice in ASP.NET use this code:
Code:
Imports System.Web.Services
Imports System.Xml.Serialization
<WebService(Namespace := "http://tempuri.org/")> _
Public Class hello
Inherits System.Web.Services.WebService
Public blabla As New retData()
<WebMethod()> Public Function HelloWorld(ByVal name As String) As retData
blabla.bla = "Hello " & name
blabla.bla2 = "Hello " & name & "!"
Return blabla
End Function
End Class
<XmlRoot("hellodata")> _
Public Class retData
<XmlElement("bla")> Public bla As String
<XmlElement("bla2")> Public bla2 As String
End Class
The Flash form has 3 fields and a button. The first field is called txtname. The others are called txthello and txthello2. The webservice has a method with 1 input parameter. The results are placed in a different class that is read by Flash.
More info about webservices