Calling Web Service using XMLHTTP Object

Follow the steps to invoke a webservice using a XMLHTTP object in javascript

Step  1: Create a soap envelope for the requested method.

soapenvelope.gif

 var envelope = <The above string>;

Step 2: Create Instance of XMLHTTP Object

Now in the Javascript method create an instance of the XMLHTTP object

 xmlhttp.gif

 Step 3: Prepare the Webservice Request

 As shown above the url points the target webservice which is Service.asmx file and named of the method is HelloWorld. The syntax to be used

url1.gif
http://<Host Name>/<Virtual Directory>/<Webservice>/Method Name

in the next line we are initiating a POST request for the webservice url.

Step 4: Handling the Callback

callback.gif

Here when the response from the web service returns it just display the return string in alert box.

Step 5: Sending the  Request

 sendrequest1.gif

As shown above, the send message is send with the envelope  for the Web Method prepare in the Step 1.

Step 6: Executing the Web Service

calloutput.gif

Refer to this link for more  http://support.microsoft.com/default.aspx/kb/893659

Advertisements

Hello World using Apollo/Adobe AIR

Its been days that I was trying to write a simple app using AIR, the buzz word these days, so downloaded the following

  1. Adobe AIR SDK.
  2. Adobe AIR SDK documentation.

Extract these above stuff after downloading. The documentation is quite good for a HTML /Javascript developer like me. Here I write a Hello World html file using AIR framework.

There are three things to be done

  1. Application XML file.
  2. HTML File.
  3. Executing the application.
Application XML File
  1. Create a XML file named <AppName>-app.xml, here appname can be HelloAIR.
  2. The structure of XML is

xml.gif

The text of rootContent element represents the name of the html file that is associated with the xml.

HTML File

The following the html code

HTML Code

The appLoad is invoked when the page is loaded. As shown above we are including the standard AIRAliases.js file in the HTML file, so AIR runtime will be initialized. If its initialized the Air.Trace statement is used to print on AIR console “Hello Air”. Then XMLHTTP request is made for getting request.txt file and dumping the content of that file onto the AIR console.

Executing the Application

When the AIR sdk is extracted there are two programs that come

  1. ADL: To execute the AIR application
  2. ADT: to package the AIR application

Use the adl command to execute the AIR application.

The ADL command

When you execute the command with XML as parameter then the following is displayed

commandline.gif

execute.gif

As shown above the Hello.AIR is the Air.Trace output and the white console displays thee content of the request.txt file.

Rich Internet Application (RIA) Comparisions

The world is really moving fast, the buzz of AJAX hasn’t gone down and the new buzz is RIA or the Rich Internet Applications. It means

Rich Internet applications (RIA) are web applications  that have the features and functionality of traditional desktop Application. (source:wikipedia)

Some of the stuff that has already come are

  1.  Microsoft Silverlight
  2. Adobe Integerated Runtime (AIR) code name Apollo
  3. JavaFX

A nice comparision between these three is provided at the below link

http://ttlnews.blogspot.com/2007/05/test_22.html

Check it out…. 

Tackling the OutOfMemoryException

Couple of months before I was quite struggling to solve one of my students problem. The problem is as follows

“The program need to read the file which stores data about many files and the file content itself.”

The program works like this

  1. Open the file.
  2. Read the metadata about each file i.e. name, size, createdon etc.
  3. Based on the length of each file, read the content of the file in one shot.
  4. Later on based on user interaction, uncompressed the selected file.
  5. Loading of the file earlier used to help it to uncompressed more faster as the content was in memory.

It works great in a normal scenario which was of size around 1 to 2 GB. But when he started stressing it out i.e a file of size sa 10GB it start failing.

We debugged the issue and found that there was a file of size 2 Gb which was trying to read and causing a OutOfMemoryException

byte[] fileContent = new byte[file.length];

Here the length was 2GB, which resulted in the said exception.

The following approach was then chosen to solve the issue

  1. Stop reading the file while reading the compressed file.
  2. This improved the performance of the app by almost 300-400%.
  3. The problem of uncompressing the file was still there.
  4. So instead of reading entire file in one chunk the file was read in many chunks.

The following is the code

remainingBytes = (long)FileLength;
bytesRead = (long)ChunkSize;
while (bytesRead > 0 && (Data = Reader.ReadBytes((int)bytesRead)) != null)
{
 	file.Write(Data, 0, (int)bytesRead);
	remainingBytes -= bytesRead;
	if (remainingBytes < bytesRead)
		bytesRead = remainingBytes;
}

The chunk size was kept configurable, so that it can be change without any code changes required.