I just posted my new CodeProject article Flex Communication with ASP.NET WebService. This article demonstrates how to communicate our ordinary ASP.NET WebService with Adobe’s Flex.
Read here: http://www.codeproject.com/KB/aspnet/FlexASPWebService.aspx
VN:F [1.9.18_1163]
Rating: 5.0/5 (2 votes cast)
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:
<?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)
My new article Flex HTTPService with ASP.NET posted to CodeProject.
Read it now
VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)
Here goes the sample code:
ASP.NET – Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select id, name, email from test",
"Data Source=localhost;Initial Catalog=test;User Id=;Password=;");
DataSet ds = new DataSet();
da.Fill(ds);
ds.DataSetName = "parent";
ds.Tables[0].TableName = "child";
Response.Write("<?xml version="1.0" encoding="utf-8"?>");
Response.Write(ds.GetXml());
}
</script>
Flex Code: HttpServiceTest.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
backgroundColor="#FFFFFF"
creationComplete="init()" >
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private function init():void{
// Send request to httpservice
hsData.send();
}
private function httpFaultHandler(event:FaultEvent):void{
// If you want to something
Alert.show("There was a problem","Error");
}
private function httpResultHandler(event:ResultEvent):void{
// If you want to something
}
]]>
</mx:Script>
<mx:HTTPService id="hsData" url="http://localhost/flextest/Default.aspx"
fault="httpFaultHandler(event)"
result="httpResultHandler(event)"
method="POST"
/>
<mx:DataGrid id="dg" dataProvider="{hsData.lastResult.parent.child}">
<mx:columns>
<mx:DataGridColumn headerText="ID" dataField="id"/>
<mx:DataGridColumn headerText="Name" dataField="name"/>
<mx:DataGridColumn headerText="EMail" dataField="email"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)
This is a working sample I made for education purpose.
- This script enables your webcam
- Show in a box the local webcam copy
- Publish to FMS (Flash Media Server)
- Receive from FMS
- Display the received (streamed) video in another Box.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="init()">
<mx:Script>
import mx.controls.Label;
import mx.controls.Alert;
import mx.core.UIComponent;
import mx.controls.Button;
import flash.net.NetConnection;
private var nc:NetConnection;
private function init():void {
// Connect to FMS
nc = new NetConnection();
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://yourfms/testlive");
}
// Fix for AS3
public function onBWDone():void{
}
private function onNetStatus(event:NetStatusEvent):void{
//Alert.show(event.info.code );
if (event.info.code == "NetConnection.Connect.Success") {
var vContainer:UIComponent = new UIComponent();
// Local webcam copy
var label1:Label = new Label();
label1.x = 0;
label1.y= 0;
label1.text = "Your webcam if you have any:";
addChild(label1);
var cam:Camera = new Camera();
cam = Camera.getCamera();
var localvid:Video = new Video();
localvid.x = 10;
localvid.y = 20;
localvid.attachCamera(cam);
vContainer.addChild(localvid);
addChild(vContainer);
// Publish
var ns:NetStream = new NetStream(nc);
ns.attachCamera(cam);
ns.publish("testlive");
}
// Re-play from FMS
label1 = new Label();
label1.x = 400;
label1.y= 0;
label1.text = "Streamed video from FMS:";
addChild(label1);
var nsPlayer:NetStream = new NetStream(nc);
nsPlayer.play("testlive");
var vid:Video = new Video();
vid.x = 400;
vid.y = 20;
vid.attachNetStream(nsPlayer);
//vid.smoothing = true;
vContainer.addChild(vid);
addChild(vContainer);
}
</mx:Script>
</mx:Application>
VN:F [1.9.18_1163]
Rating: 3.7/5 (3 votes cast)
Recent Comments