Tuesday, July 03, 2007

AJAX, Flex, Web Services...(oh my!)

So I've been playing around with AJAX and Flex quite a bit lately. Seems a lot of people I talk to are interested in these technologies and I must say, they are pretty cool. Especially the ASP.NET AJAX Extensions and Toolkit. I installed a copy of Flex Builder and went through about 16 hours worth of Flex training but it didn't excite me near as much as watching the AJAX for ASP.NET videos.

With all the hype surrounding the whole Web 2.0 craze lately, seeing so many sites with AJAX and Flex popping up, realizing sites you go to everyday are now incorporating more and more "really cool" features...it definitely feels like things are changing quickly. Although Flex is sort of considered to be an alternative to AJAX, I think knowing how to work with both is the smart way to go right now. Obviously the more you know, the more powerful you are but in this case, I can see how each would serve their own unique purpose. Similar to the way technologies like Flash and Java do.

The main thing I'm interested in right now though is getting really knee deep into the inner workings of so-called Web 2.0 applications. When writing ASP.NET applications, Visual Studio has always been great for dragging and dropping controls, auto-generating code, and of course hiding that code from you. Making complex tasks very easy, or seem very easy thus requiring less overall knowledge to accomplish. It's no different with AJAX for ASP.NET. What requires a click and a drag within Visual Studio might seemingly take hours to code by hand in PHP. But the amount of time spent dealing with it's quirkiness could be about the same.

I spent the last 6 or so hours fighting with a "simple ASP.NET AJAX" application. Not to be outdone, I spent about 8 hours yesterday fighting with a simple Flex application. I decided to update my MP3 database and create a data access class in C# that I could use with various other applications. For instance, I created a search page in ASP.NET with a datagrid for the results. Then I created a web service that performed the database functions and hooked the ASP.NET page up to that. Finally, I wanted to create a Flex application to connect to the web service. Ran into quite a few snags here and there mainly because I was trying to return a DataSet object from the web service method call.

Flex and Microsoft web services don't seem to play well together just yet. Retrieving DataSet data in Flex can be a little tricky. For instance, you cannot actually send a true DataSet object. You have to return a DataTable object. Flex then reads it in as an ArrayCollection.

Then again, ASP.NET AJAX and Microsoft web services don't seem to play that well together either. Using the same web service that I had the ASP.NET page and Flex application working with, I then AJAX enabled the ASP.NET page. This worked beautifully! I was amazed! I thought how can this be so easy?? Well, the problems arose when I decided to add the code to call the web service methods using client side javascript functions. This concept is the true essence of AJAX technology and is at the core of why AJAX is really powerful. So it definitely cannot be overlooked. But it also proves to be the most nerve racking concept! Of course!

What caused such a headache earlier was the fact that when you call a web service using javascript, you have to use a relative path that points to a local copy of the *.asmx file. This means that the web service must be local in order to access it using client side javascript calls. This pretty much defeats the purpose of a web service. Ok not entirely, but web services are essentially meant to be remotely called over the web...or over a network. So for the service to have to be local just didn't make much sense to me.

Well, come to find out...it is possible to reference a remote *.asmx file via a URL address, but to do so you have to create a bridge between the javascript and the web service. In other words it's the same as creating a proxy like you would with a PHP implementation. I haven't had a chance to experiment with this yet but I plan to in the next couple days. There really isn't a whole lot of information out there yet on this stuff because it's still so new but I have a few books here that should help.

Ok now, back to the fun...

Thursday, May 10, 2007

Linux - Project archiving made simple

When I'm working on an application I periodically save the entire directory structure the project resides in, usually upon the completion of any major milestones or prior to any dirty work. The number of archive files can add up over time so to keep track of them I use a handy little naming convention -> Project_yyyyMMddhhmm. The reason for this, other than consistency is pretty simple... By using the current date/time in this format, all the archive files are automatically sorted alphabetically by the exact year, month, day and time they were created and well, it makes more sense than say "Project1, Project2" etc...

If I'm working in Windows I usually go about the process of archiving a project by selecting all the files/folder in the working directory, adding them to a zip file then naming the zip file according to the naming convention. In the process I have to look at the current date/time and populate the information accordingly. This takes less than a minute...but when under tight deadlines, every minute counts!

In Linux/Unix, I can archive a project in less than a second...through the use of a few aliases and a single variable. For example, I have the following in my .bashrc file:

alias appname='echo $appname'
alias archtime='date +%Y%m%d%M'
alias archapp='tar -cf `appname`_`archtime`.tar *'

So, I have a shell variable called appname which, in BASH I can change by typing appname='currentapp'. Then I have a command called appname which simply returns the value of that variable. Finally, I have two commands: archtime and archapp which retreive the date and archive the entire directory respectively. The archtime command simply returns the formatted results of a date command and the archapp command uses the tar application to archive the directory using the results of the appname and archtime commands.

Now I can run archapp from the command line and it will automatically create a new archive file using my naming convention :) Simple but sweet!

Wednesday, January 10, 2007

Oracle - Unable to access admin console for local database

Summary: I set up my laptop as a development system to work on a JSP application which connects to an Oracle 10g database. I had installed Oracle locally on my laptop a few times and finally got a stable version up and running, although I still run into issues here and there. One of the problems I was experiencing recently was being unable to open the administration page for a local database I created. It was only happening intermittently and seemed to be related to having multiple network interfaces enabled. If I disabled all of the interfaces I wasn't using, and left only the one I needed, then it would usually work. However, this poses a problem when I must have more than one interface enabled, such as when connected to another network via a VPN. After much research, I found quite a bit of information about this problem. Seems it is rather common.
Resolution: Most times, the fix for the problem is to install and configure the Microsoft Loopback Adapter. Also, the local hosts file may need to be modified. Details on how to do this can be found easily on the web by doing a quick search for "installing microsoft loopback adapter". Also, if you throw an "oracle" in the search somewhere, you'll find a lot of info related to this specific issue. Here's someone else who was experiencing a similar problem. http://oracleplz.blogspot.com/2006/02/10g-installation-on-windows.html
You may need to verify that the admin port is listening as well. You can test this by running telnet from the command line. For instance, telnet computername 5500. If the connection fails, run a netstat -a command and make sure that the computer is listening on the specfied port. If the system is not listening on the port, then the service is probably not started. To manually start the database service, open up the service list in Windows and make sure that the OracleDBConsole service is started. If it's unable to start, you may need to manually restart the OracleService service.

Wednesday, December 20, 2006

Web Development - 127.0.0.1 works but localhost doesn't

Summary: I ran into an issue recently when I was setting up a new computer as a development system. I was using Netbeans as my IDE. In order to develop and test JSP applications, I needed to install Tomcat. Once I had everything installed and configured, I built and ran an application that I knew worked because it was running fine on a different computer. Same configuration, same source code but was unable to run it on the new computer. The issue was that I was receiving an HTTP 500 - Internal Server Error when attempting to access any web pages on the computer using http://localhost as the URL. The first thing I should have tried was attempt to access the application using http://127.0.0.1/ instead of http://localhost/. But instead, I proceeded to uninstall and re-install everything! Including all of the Java components. When this didn't work, I tried installing the Sun Java Application Server thinking there might be something wrong with Tomcat. This didn't work either. I checked the local hosts file and didn't see anything out of the norm. After fighting with this issue for a few days, I finally figured out what the problem was and how to fix it, but till this day could not tell you why the problem exists.

Resolution: After comparing all of the configuration options on the computer that worked with the one that didn't, I noticed that the only difference was that the new computer's browser was configured to use a proxy server. When I removed the proxy configuration from the browser settings, I was then able to access all locally hosted applications using the http://localhost/ URL as well as the http://127.0.0.1/ URL. Who knows why....