Anonymous,

Please Login or Register
Download Nuke Evolution today for a CMS you can enjoy using and sharing with your friends!

[ Download Now ]
Main Menu   
 
HomeHome  
    Home
Members  
    Profile
    Your Account
Community  
    Forums
Statistics  
    Statistics
    Top 10
Files & Links  
    Downloads
News  
    News
Other  
    Tutorials
    Content
    FAQ
    Site Map
Search   
 


Tutorials: Weborb Server Connecting to C# Assembly using Flex


Description:
Open in new window


What we are going to do in this tutorial is to create a C# assembly to connect to MySQL database and return the information using a presentation server back to the Flex application using Flex RemoteObjects. This sounds difficult?


Version: 1.0
Added on: 28 May 2011
Author: David Welford-Costelloe
Difficulty Level: Easy
Views: 153
Detailed Profile
Rate Resource

Weborb Server Connecting to C# Assembly using Flex


Well let us see if this is the case.



What do we need for this Tutorial?





1.MySQL Database (community addition)



2.WebORB Presentation server for .NET (community addition)



3.Visual Studio 2008 C# - Express edition (free)



4.MySQL Database GUI tools



5.Flash Builder 4 (60 day trial version)



This tutorial will be generated on Microsoft Windows Vista, now let us get down to business.



Download and install these tools:



1.Your choice either C# or VB.NET (I like C#) http://www.microsoft.com/express/Downloads/



2.MySQL Server http://dev.mysql.com/downloads/



3.MySQL GUI Tools http://dev.mysql.com/downloads/gui-tools/5.0.html



4.MySQL connector for .NET http://dev.mysql.com/downloads/connector/net/6.2.html



5.Flash Builder 4 https://www.adobe.com/cfusion/tdrc/index.cfm?product=flash_builder



6.WebORB Presentation server for .NET

http://www.themidnightcoders.com/prod … orb-for-net/overview.html



Install all of the above and make sure you keep the root admin account password handy for MySQL Database. I am fortunate to have a Team developer version of Visual Studio 2008 which I will be using in this demo which is similar to the express version you have downloaded. First off we will build the MySQL Database and Tables:



Open in new window



Open in new window







MySQL Database Configuration



Create a simple database and table to read. Open the MySQL Query Browser part of the MySQL GUI tools installed.



Enter the root password you setup during installation and click OK



Open in new window



Open in new window





Right click the Schema Tab and select Create New Schema (CTRL-N)



Enter DemoSample as the name and click OK:



Right Click demosample Schema and select create Table:



Open in new window





Create the following table and Fields:



Open in new window





Make sure user_id is primary key and Auto Increment.



Open in new window





Click Execute.



Open in new window





Insert the following records:



Open in new window





Sample after insertion:



Open in new window







Build C# Assembly

Open Visual Studio C#:

If you are using Vista make sure you open this as administrator.



Open in new window

Open in new window





Open in new window





Create a new Project (in this demo this is C#)



Open in new window





Select Visual C# and Class Library and name it MySQLDemo and click ok



Open in new window

Open in new window



Open in new window





Rename the Class1.cs to MySQLDemo.cs



1. Add reference to MySQL connector

Open in new window





2.Right click the solution explorer references and Add MySqlData reference



3.Add the following reference MySql.Data



4.Add the following references to your code





using MySql.Data.MySqlClient;

Using MySql.Data.Types;







Open in new window

Open in new window





C# Assembly Code











using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using MySql.Data.MySqlClient;

using MySql.Data.Types;

using System.Data;



namespace MySQLDemo

{



public class 
MySQlDemo

{



private 
MySqlConnection myConnection;

private 
MySqlDataAdapter myDataAdapter;

private 
DataSet myDataSet;

private 
string strSQL String.Empty;



public 
DataSet getUserInformation()

{



myConnection = new MySqlConnection ("server =localhost; user id=root;password=yourrootpassword; database=demosample; pooling=false;");





strSQL "SELECT * FROM userlist";



myDataAdapter = new MySqlDataAdapter(strSQLmyConnection);



myDataSet = new DataSet();



myDataAdapter.Fill(myDataSet,"UserList");



myDataAdapter.Dispose();



return 
myDataSet;



  }



 }



}








Above is the complete code for the MySQL Database connection, all we are doing is getting the list of records in the table. Compile the DLL as release and deploy to the WebORB Server.



Open in new window

Open in new window





Install WebORB Server



Download the WebORB Server for .NET:

http://www.themidnightcoders.com/prod ... rb-for-java/overview.html



Install the WebORB by following the instructions once completed open a browser and go to:







http://localhost/weborb30







Above will be the screen to show you have successfully installed WebORB. The next item is to deploy the .NET assembly to WebORB. This can be completed two ways:



1.Using the Deployment Tab on the Console



2.Copy the dll to the WebORB bin directory



In this demo we will be using the WebORB console Deployment Tab



Open in new window

Open in new window









Click on the Deployment Tab and select the button ‘Deploy Assembly’



Open in new window



Open in new window





Select the folder where Visual Studio .NET has compiled the assembly



Open in new window





Select Open you will now see the assembly deployed



And that is it for Deploying to WebORB Presentation Server. Next we will build the Flash 4



Using Flex SDK 4.0.



Open in new window





Building Flash Builder 4 Application



This application will need to be configured to use ASP.NET. Each step required will be outlined:



Open in new window





1.Create New Flex Project File ==> New ==> Flex Project



Open in new window





2.Because I also use the Flash Builder 4 for my Flex 3.5 SDK projects I configure the Flex 4 SDK manually:



3.Make sure Application Server Type is set to ASP.NET and click Next

Open in new window





4.On this page we configure the WebORB Server using IIS



5.Check User Internet Information Services (IIS)



6.Web application root: Select Browse to where you installed WebORB virtual directory



7.Web application URL:





http://localhost/weborb30






Open in new window





8.Click Validate Configuration



Open in new window





9.Click Next



10.Click Finished to build the project structure



Open in new window

Open in new window



Open in new window

Open in new window



Open in new window

Open in new window





Now we need to connect to the WebORB server and call the .NET assembly to get our information back from the MySQL Database.



1.Open your browser to



http://localhost/weborb30






2.This time we are going to use the Management Tab to generate the required code for the Flash Builder.



Open in new window

Open in new window



Open in new window





3.Click on the right section MySQLDemo.DLL Expand to getUserInformation



4.Here we are going to test the Assembly DLL to make sure it works. Click on the Invoke button.



Open in new window





5.You can now see the results of the assembly



Open in new window





6.All is well now we will generate the required code for the Flash Builder – Click up one level to generate Code



Open in new window





7.As you can see we now have all the code required.

Open in new window





8.Two action script classes have been generated Click the download button and save the code to a folder:



Open in new window



Open in new window

Open in new window





In my case I saved to DocumentsFlexCode



9.Extract the contents of the zip file:



A folder call MySQLDemo has been created now we need to drag and drop this folder into out Flash Builder project.



Open in new window





10.Drag the folder to the 'src' directory in the project



Open in new window





11.The package MySQLDemo with action script classes has been generated for you



Open in new window





12.Now we will create a simple Datagrid to hold the information from the assembly



Open in new window





13.Click on Source to bind the classes



Open in new window





14.Remove the columns from the grid as these will be auto generated for this demo





                    

<s:HGroup x="238" y="120" width="573" height="280"



    <
mx:DataGrid id="mydataGrid" width="571" height="279"/>



</
s:HGroup>







15.Add the Script tags







 <fx:Script>

    <![
CDATA[



    ]]>

 </
fx:Script>







16.Look at the MySQLDemoModel.as code file



Open in new window





17.Copy the highlighted code to the Script section



Open in new window





18.Add a function call getUsersFromMySQL

Open in new window





19.Select serviceProxy.getUserInformation();



Open in new window





20.Set the DataGrid DataProvider to:





dataProvider="{model.getUserInformationResult}"







Open in new window





21.Add creationComplete



Open in new window





22.Set the creationComplete="getUsersFromMySQL()"



23.Now we need to add a parameter to the Flash Builder Compiler to invoke the WebORB configuration. Right Click the project and select properties



Open in new window





24.Select the Flex Compiler



Open in new window





25.In the Additional compiler arguments add the following:

Open in new window











-services c:Inetpubwwwrootweborb30web-infflexservices-config.xml







26.Click OK to save and run the application



Open in new window





I added a little bit of code from Tour De Flex samples to make it more appealing



Open in new window

Open in new window





That is it we have now connected to a .NET assembly and had the assembly connect to MySQL database and return the information to our Flash Builder project. enlightened

Tutorials ©