|
Adobe AIR Web Service Hello World test application |
I've recently been looking at putting together some AIR applications. I've used FLEX for a few years now, and have only just come up with some useful AIR ideas, so I thought I'd build an application or two.
Usually I would use flash remoting, but I haven't spent too much time investigating how this works in AIR, so I've opted for the old school Web Service.
In the middle of my newest AIR application I stumbled upon an issue. No matter what I did I was receiving a 'HTTP Error' response from my Web Service. After stumbling around in the dark for a while tweaking code to no avail, I decided to write the most basic Web Service I could think of.
So here is 'Hello World', as a Web Service call from AIR.
Firstly create a call to your Web Service. In this case it was a local file. Point the wsdl variable at the fully qualified path to your service. I am using a coldFusion back end, so it is a CFC. This is also where you specify the fault handler and result handlers. You can add as many 'operation' methods here as you want, that way you address specific functions in your service individually.
2 <mx:operation name="sayHello" fault="faultHandler(event)" result="resultsHandler(event)" />
3 </mx:WebService>
4 <mx:Button x="10" y="10" label="Click me" click="getData()"/>
5
6</mx:WindowedApplication>
I've also added a button that will call a function to action the service call.
Next we will add the functions.
2<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
3
4<mx:Script>
5 <![CDATA[
6 import mx.rpc.events.ResultEvent;
7 import mx.rpc.events.FaultEvent;
8 import mx.controls.Alert;
9
10 private function getData():void{
11 getMessages.sayHello();
12
13 }
14
15 private function faultHandler(event:FaultEvent):void
16 {
17 Alert.show("Error: " + event.fault.faultString, "Application Error");
18 }
19
20 private function resultsHandler(event:ResultEvent):void
21 {
22 Alert.show(String(event.result))
23
24 }
25
26 ]]>
27</mx:Script>
A getter function, that will actually send the Service request, a fault handler that will simply Alert the user to a fault event, and a result handler that Alerts the user to whatever message is returned from the Web Service.
The CFC
The CFC service is a simply object to return a string. Just make sure that your 'Access' is set to remote.
2
3
4 <cffunction name="sayHello" displayname="sayHello" hint="it says hello" access="remote" output="true" returntype="String">
5
6 <cfset var message = "Hello world">
7
8 <cfreturn message/>
9 </cffunction>
10
11</cfcomponent>
So we end out with:
|
Adobe releases Tour-de-Flex as Eclipse plugin |
I was directed to the Adobe Developer Connection site by a colleague the other day, and told to go look at 'Tour-de-Flex'.
Its an AIR/Web application that hosts a whole range of example FLEX and AIR resources.
Its also available as a handy eclipse plugin, if you are that way inclined :-)
I've had a brief look around it, and it looks pretty good, very handy having code examples and themes right there on your desktop.
Also gave me some interesting trains of thought of the next AIR application I have in mind....
|
SQL Stored Procedures, UPDATE Template script |
This article deals with creating a SQL stored procedure for Updating a record.
In each of these stored procedure templates I am declaring a variety of documentation parameters in the header.
I've found these handy in the past when you are working in a team environment, or when you go back to a procedure at a later date. Its much easier to read a simple description in the header, than trawl through the SQL code looking for what it is doing.
So, this declares the procedure name, any parameters and return codes, and also details what it does, and who made it.
In a modified version of this I also hold the SVN revision number here.
2/* Company Name */
3/********************************************************************************/
4/* Procedure Name : dbo.ssp_stored_procname */
5/* Parameters : */
6/* Return Codes : */
7/* */
8/* Description : Description of what it does, params etc */
9/* */
10/* */
11/* */
12/* */
13/* */
14/* Author : Authorname */
15/* Date written : Date */
16/* History : version number */
17/* */
18/********************************************************************************/
The next block of code performs a select on the sysObjects table (part of the Master database). It is checking for the existence of itself. If it finds itself, it will drop the procedure. Note that throughout all of these scripts we are telling the user at each stage what is going on, by printing useful english output back to the screen.
2BEGIN
3 PRINT 'Dropping old version of dbo.ssp_stored_procname'
4 DROP PROCEDURE dbo.ssp_stored_procname
5END
6GO
By now we have identified whether or not the procedure previously existed, and if it did, we have dropped it, so we know that we are all good to go. So to create our Update procedure, we print out a message to the user, then using the "CREATE PROCEDURE" command we create our procedure.
At this point you substitute the "@field" value with your field name, and the [datatype] and (datasize) with the correct values. Just list your fields one after another, seperating with a comma. As this is creating an Update stored procedure I will list any of the values to update in the query here.
2GO
3
4CREATE PROCEDURE dbo.ssp_stored_procname
5 (@field [datatype](datasize),
6 @field [datatype],
7 @field [datatype](datasize),
8 @field [datatype](datasize),
9 @field [datatype],
10 @field [datatype])
After that we create the SQL code, as per usual. We have an Update statement, using the variables declared above in the SQL variable declaration (@var). Just write out your update like you normally would here. Then we check for any errors, and return a success message if it all worked ok!
2SET [field] = @field,
3 [field] = @field,
4 [field] = @field,
5 [field] = @field,
6 [field] = @field
7WHERE
8 ( [field] = @conditions)
9RETURN @@ERROR
10GO
11PRINT 'Creating procedure dbo.ssp_stored_procname - END'
12GO
Download the full template here.
|
SQL Stored Procedures, DELETE Template script |
This article deals with creating a SQL stored procedure for deleting a record.
In each of these stored procedure templates I am declaring a variety of documentation parameters in the header.
I've found these handy in the past when you are working in a team environment, or when you go back to a procedure at a later date. Its much easier to read a simple description in the header, than trawl through the SQL code looking for what it is doing.
So, this declares the procedure name, any parameters and return codes, and also details what it does, and who made it.
In a modified version of this I also hold the SVN revision number here.
2/* Company Name */
3/********************************************************************************/
4/* Procedure Name : dbo.ssp_stored_procname */
5/* Parameters : */
6/* Return Codes : */
7/* */
8/* Description : Description of what it does, params etc */
9/* */
10/* */
11/* */
12/* */
13/* */
14/* Author : Authorname */
15/* Date written : Date */
16/* History : version number */
17/* */
18/********************************************************************************/
The next block of code performs a select on the sysObjects table (part of the Master database). It is checking for the existence of itself. If it finds itself, it will drop the procedure. Note that throughout all of these scripts we are telling the user at each stage what is going on, by printing useful english output back to the screen.
2BEGIN
3 PRINT 'Dropping old version of dbo.ssp_stored_procname'
4 DROP PROCEDURE dbo.ssp_stored_procname
5END
6GO
By now we have identified wether or not the procedure previously existed, and if it did, we have dropped it, so we know that we are all good to go. So to create our Insert procedure, we print out a message to the user, then using the "CREATE PROCEDURE" command we create our procedure.
At this point you substitute the "@field" value with your field name, and the [datatype] and (datasize) with the correct values. Just list your fields one after another, seperating with a comma. As this is creating a delete stored procedure I will only be inserting one variable into the query.
2GO
3
4CREATE PROCEDURE dbo.ssp_stored_procname
5 (@field [datatype](datasize))
After that we create the SQL code, as per usual. We have a Delete statement, using the variable declared above in the SQL variable declaration (@var). Just write out your delete like you normally would here. Then we check for any errors, and return a success message if it all worked ok!
2WHERE (conditions = @var)
3RETURN @@ERROR
4GO
5
6PRINT 'Creating procedure dbo.ssp_stored_procname - END'
7GO
By using a script like this I've found that its really simple to have a repeatable standard process that is easy to implement across a team of developers, ensuring you get the same results, no matter who writes the query. It is also very useful if you have a seperate implementation team, as these scripts are re-runnable, they clear up after themselves.
Download the full template here.