ASP .NET Source Code

Feb 9, 2010 at 9:17 AM

I am struggling to convert your example file into ASP code instead of C#

[AMFEnabled("Kamacho.Samples.DTO.InvoiceDTO")]
public class InvoiceDTO
{
    [AMFProperty(AMFDataType.Guid, "id")]
    public Guid Id;

    public InvoiceDTO()
    {
       
    }
}

What is the  ASP equivalent of AMFEnabled/AMFProperty?

Thanks

Coordinator
Feb 9, 2010 at 2:40 PM

I can imagine, this isn’t convertible to ASP code.  If you are using any other language supported by ASP.NET you should be ok.

From: luckyknight [mailto:notifications@codeplex.com]
Sent: Tuesday, February 09, 2010 2:18 AM
To: steve.klee@yahoo.com
Subject: ASP .NET Source Code [dotnetflex:83634]

From: luckyknight

I am struggling to convert your example file into ASP code instead of C#

[AMFEnabled("Kamacho.Samples.DTO.InvoiceDTO")]
public class InvoiceDTO
{
[AMFProperty(AMFDataType.Guid, "id")]
public Guid Id;

public InvoiceDTO()
{

}
}

What is the ASP equivalent of AMFEnabled/AMFProperty?

Thanks

Read the full discussion online.

To add a post to this discussion, reply to this email (dotnetflex@discussions.codeplex.com)

To start a new discussion for this project, email dotnetflex@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Feb 9, 2010 at 6:46 PM
Edited Feb 9, 2010 at 6:48 PM

Thanks for your reply. I actually meant ASP .NET (VB).

I have since converted it and have it working. It's taken me a few days to get to work due to lack of examples that show both VB .NET and flash application (without flex). I also had to learn flash and ActionScript from scratch but we will not go there!! :)

For reference, here is the VB equivalent:

<AMFEnabled("Kamacho.Samples.DTO.InvoiceDTO")> _
Public Class InvoiceDTO

 <AMFProperty(AMFDataType.Guid, "id")> _
 Public Id As Guid

 Public Sub New()
 End Sub

End Class 

Coordinator
Feb 9, 2010 at 7:11 PM

My bad, hopefully I didn’t come off too snobbish.  I literally threw the code out there hoping someone might benefit from something we use in all of our apps.  I will be (and I can’t commit to anything) putting out a lot more example code and an entire app example you could run to see how it all fits together.

Hope it helps you,

Steve

From: luckyknight [mailto:notifications@codeplex.com]
Sent: Tuesday, February 09, 2010 11:47 AM
To: steve.klee@yahoo.com
Subject: Re: ASP .NET Source Code [dotnetflex:83634]

From: luckyknight

Thanks for your reply. I actually meant ASP .NET (VB).

I have since converted it and have it working. It's taken me a few days to get to work due to lack of examples that show both VB .NET and flash application (without flex).

For reference, here is the VB equivalent:

<AMFEnabled("Kamacho.Samples.DTO.InvoiceDTO")> _
public class InvoiceDTO

<AMFProperty(AMFDataType.Guid, "id")> _
Public Id As Guid

Public Sub New()
End Sub

End Class

Read the full discussion online.

To add a post to this discussion, reply to this email (dotnetflex@discussions.codeplex.com)

To start a new discussion for this project, email dotnetflex@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Feb 11, 2010 at 10:40 AM

Hi Kamacho, Thank you for your reply. I have programming .net for a couple of years now but flash/actionscript is something new to me. So it's been hard work to get it going as I've had to search all over the net for help on getting this going.

I am now able to read data using my flash app using the webservice. Now I am trying to send data from flash, I believe I have worked out how to do this using the request.parameterlist in .net.

On a side note, would it be possible to add another function to the AMFProcessor class? One that checks the inputstream has any data. E.g. it could be called HasInputStream() or whatever. I could use this in my code before ProcessHttpRequest to check for any input to avoid an exception being raised.

 

Thanks.

Kamacho122 wrote:

My bad, hopefully I didn’t come off too snobbish.  I literally threw the code out there hoping someone might benefit from something we use in all of our apps.  I will be (and I can’t commit to anything) putting out a lot more example code and an entire app example you could run to see how it all fits together.

 

Hope it helps you,

Steve

Feb 11, 2010 at 1:50 PM
Edited Feb 11, 2010 at 2:36 PM

OK So I'm stuck. I wish to pass a object I have created in ActionScript to the .net application. The class extends the Object class.

But I get an error message in dotnetflex ("AM3 is not supported") ? The parameter.data is empty.

Update: If I use ObjectEncoding.AM0 it works!

 

luckyknight wrote:

Hi Kamacho, Thank you for your reply. I have programming .net for a couple of years now but flash/actionscript is something new to me. So it's been hard work to get it going as I've had to search all over the net for help on getting this going.

I am now able to read data using my flash app using the webservice. Now I am trying to send data from flash, I believe I have worked out how to do this using the request.parameterlist in .net.

On a side note, would it be possible to add another function to the AMFProcessor class? One that checks the inputstream has any data. E.g. it could be called HasInputStream() or whatever. I could use this in my code before ProcessHttpRequest to check for any input to avoid an exception being raised.

 

Thanks.

Coordinator
Feb 11, 2010 at 2:35 PM

One thing that is missing from the examples so far is how you make the calls from your flash app to work with our AMF processor.  A few things you need to know:

1) We don't support AMF3, when we started this project it was before Adobe released their documentation for the AMF Spec and we had a lot of problems and misleading information related to AMF3 - so it currently only supports the first AMF format - which is still supported by the new versions of Flash and is still a very good format for sending data over the wire

2) You need to use the NetConnection objects in Flash to make these calls

 

--- Examples ---

We are using the simple event driven Cairngorm architecture in our Flex solutions, so these examples are "Command/ServiceDelegate" driven but you can see how we make a call to the .NET back-end.

 

ServiceLocator

A static class we use to define the location for the main .aspx page that will be handling the various calls from Flex.  In this class we set the default object encoding to AMF0 which gets rid of the error you are seeing and defines all of the endpoints for our communications.  Here is the full source for this below:

 

 

package Kamacho.Example.Services
{
import flash.net.*;
import flash.events.*;
import com.adobe.cairngorm.*;
import mx.rpc.*;
import mx.core.*;
import mx.controls.*;
import Kamacho.Example.*;

public class ServiceLocator
{
private static var _instance:ServiceLocator;

internal var services:Object;

public function ServiceLocator():void
{
if(_instance != null)
{
throw new CairngormError(CairngormMessageCodes.SINGLETON_EXCEPTION, "ServiceLocator");
}

_instance = this;

LoadServices();

NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
}

private function LoadServices():void
{
services = {};

var location:String = Application.application.parameters.serviceProtocol + "//" +
Application.application.parameters.serviceHost;

var appLocation:String = Application.application.parameters.mainPath;
if(appLocation == null || appLocation == "")
appLocation = "/www/";

services["Common"] = location + appLocation + "FlexService.aspx";
services["CommonSecure"] = "https://" + Application.application.parameters.serviceHost + appLocation + "FlexService.aspx";
}

public static function getService(name:String):String
{
if(_instance == null)
_instance = new ServiceLocator();

return _instance.services[name];
}


}

}

 

 

Notice we are only defining 2 locations (Common, CommonSecure) which both point to the same .aspx web page (acting as our service).  Now I will show you an example of how we actually make a call from Flash to .NET.

 

Example of Flash calling into the Web Back-End

We raise events in Cairngorm to call into the back-end.  The events are handled by Command classes that use Delegates to make a call.

Here is our BaseDelegate class that all of our service classes extend:

 

package Kamacho.Example.Services
{
	import flash.net.*;
	import flash.events.*;
	import mx.rpc.*;
	import Kamacho.Example.*;
	import mx.core.*;
	
	public class BaseDelegate
	{
		protected var myResponder:IResponder;
		
		public function BaseDelegate(responder:IResponder) : void
		{
			myResponder = responder;
		}
		
		protected function getService(name:String):NetConnection
		{
			var conn:NetConnection = new NetConnection();
			conn.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			conn.connect(ServiceLocator.getService(name));
			return conn;
		}
		
		protected function getCommonService():NetConnection
		{
			return getService("Common");
		}
		
		private function netStatusHandler(event:NetStatusEvent):void
		{
			myResponder.fault(event);
		}
		
		protected function handleSuccess(event:*=null):void
		{
			myResponder.result(event);
		}
		
		protected function handleFault(event:*=null):void
		{
			myResponder.fault(event);
		}
	}
}

 

And then here is an actual implementation of that base delegate:

 

package Kamacho.Example.Services
{
	import flash.net.*;
	import flash.events.*;
	import mx.rpc.*;
	
	public class ExampleDelegate extends BaseDelegate
	{
		public function ExampleDelegate(responder:IResponder) : void
		{
			super(responder);
		}
		
		public function exampleWithoutParameters():void
		{
		    var service:NetConnection = getCommonService();
			service.call("Example.WithoutParameters",
				new flash.net.Responder(handleSuccess, handleFault),
				null);
		}
		
		public function exampleWithParameters(p1:String, p2:ExampleDTO, p3:int):void
		{
		    var service:NetConnection = getCommonService();
			service.call("Example.WithParameters",
				new flash.net.Responder(handleSuccess, handleFault),
				p2, p2, p3);
		}
		
	}
}

 

To create an instance of the delegate you have to pass in an ActionScript class that implements IResponder - these are our Command classes. 

Command Class Example

In this example I am trying to weed out the Cairngorm stuff so you can just focus on the delegate piece (which is not Cairngorm specific). mx.rpc.IResponder has two methods you must implement:

 

public function fault(info:Object):void {}
public function result(data:Object):void {}

 

 

Here is a simple command class that calls into the back-end methods shown above:

 

package Kamacho.Example.Commands
{
import Kamacho.Example.Services.*;
import Kamacho.Example.*;
import mx.rpc.*;
import flash.net.*;
import mx.controls.*;

//loads up the application
public class ExampleCommand implements IResponder
{
private var _delegate:ExampleDelegate;
public function callExampleWithoutParameters():void
{
_delegate = new ExampleDelegate(this);
_delegate.exampleWithoutParameters();
}


 

   public function callExampleWithParameters(name:String, example:ExampleDTO, refId:int):void
{
_delegate = new ExampleDelegate(this);
_delegate.exampleWithParameters(name, example, refId);
}

 

		
public function fault(info:Object) : void
{
//do error handling here
}


public function result(data:Object) : void
{
//do result handling here, the data
//object will be your response object
//from .NET
}


}
}

 

 

Hopefully that helps you and you can piece it all together with the rest of the ASP.NET example code on the website. If you make your calls this way there is never a need to check for an input stream because there is always a method being called (which is part of the AMFRequest).

Here are a few snippets of how this might be handled in FlexService.aspx:

 

1) the page load

 

protected void Page_Load(object sender, EventArgs e)
	{
		_processor = new AMFProcessor(Request, Response);
		_processor.Command += new AMFProcessor.AMFCommandHandler(processor_Command);

		_processor.ProcessHttpRequest( );
	}

 

2) handling of the commands

 

void processor_Command(AMFClientRequest request)
	{
		switch (request.Command)
		{
			case "Example.WithoutParameters":
				handleWithoutParameters(request)
  break; case "Example.WithParameters": handleWithParameters(request); break; default:
 break; } }

 

 

3) the handlers

 

private void handleWithoutParameters(AMFClientRequest request)
{
//do something and return a response
ActionScriptObject aso = new ActionScriptObject();
aso.AddProperty("success", AMFDataType.Boolean, true);
request.Response = aso;
}

private void handleWithParameters(AMFClientRequest request)
{
string name = request.getString(0);
ExampleDTO example = request.getTypedObject(1, typeof(ExampleDTO)) as ExampleDTO;
int refId = request.getInt(2);

//do something and return a response

ActionScriptObject aso = new ActionScriptObject();
aso.AddProperty("success", AMFDataType.Boolean, true);
request.Response = aso;
}
Feb 11, 2010 at 3:35 PM
Edited Feb 11, 2010 at 3:35 PM

Thanks for your help. I have now got my .net and flash application communicating both ways :)

LuckyKnight.

Coordinator
Feb 11, 2010 at 4:04 PM

No problem, glad you are having success!

From: luckyknight [mailto:notifications@codeplex.com]
Sent: Thursday, February 11, 2010 8:35 AM
To: steve.klee@yahoo.com
Subject: Re: ASP .NET Source Code [dotnetflex:83634]

From: luckyknight

Thanks for your help. I have now got my tester flash application working :)

LuckyKnight.

Read the full discussion online.

To add a post to this discussion, reply to this email (dotnetflex@discussions.codeplex.com)

To start a new discussion for this project, email dotnetflex@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com