Browse DevX
Sign up for e-mail newsletters from DevX


Develop for the SmartPhone Using Techniques You Already Know : Page 2

The form factor is new, but developing applications for these cutting-edge devices is mostly old hat. Armed with just a few additional principles and warnings, you can be making apps for SmartPhones long before the rest of the pack.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Adding a Web Reference
The sample application in this article retrieves stock quotes from a public Web service at http://www.webservicex.net/stockquote.asmx. Add a reference just as you would in any .NET application, by. right-clicking the project name in the Solution Explorer and choosing Add Web Reference. I gave the Web reference name as StockWS. This Web service has a single method called GetQuote, which takes a stock symbol as a parameter and returns a variety of information such as the Opening price, High, Low, Earnings, Last price, etc. in an XML format. Once you have added the Web service you need to invoke it in code.

Figure 4. The Application UI: The working application will accept a stock quote in a TextBox control.
Creating the Application UI
The UI for this sample application is very simple: It allows the user to enter a stock symbol and it displays the resulting stock quote (see Figure 4).

You need to place two label controls and one TexBox control on your form. I enlarged the Label2 control to fit the rest of the form, in order to best accommodate the returned values from the Web service. Next, modify the text property of the Label1 control to "Enter Stock Symbol" and leave the text property of both Label2 and TextBox1 blank. That's all the UI you require.

Calling the Web Service
Double-click the Go menu option to open its client event, and enter the following code:

Label2.Text = "Getting Stock Quote..." Me.Refresh() Dim myService As StockWS.StockQuote = New StockWS.StockQuote Label2.Text = myService.GetQuote(TextBox1.Text)

Because we're calling a Web service that I know is going to take some time to retrieve data, I decided to change the text of Label2 to warn the end user. Be aware that sometimes, even though you change the text of a control in code, the change doesn't seem to occur. Therefore you need to be sure to call the form's refresh method. This will force the window to invalidate its client area and immediately redraw itself and any child controls. The next two lines of code instantiate the Web service and change the TextBox1 text property to reflect the returned values.

Deploying the Application
Hitting F5 will pop up the deployment options dialog box.

For deployment, you have three choices: deploy your application to an actual SmartPhone device, deploy it to an emulator that connects to radio device attached to your machine, or deploy to an emulator that simulates a radio (Virtual Radio). The Virtual Radio emulator is an actual copy of the device OS that loads up in a virtual machine within your desktop operating system. This ensures you're working with the actual bits that would be on the device.

Author's Note: The Virtual Radio emulator isn't a replacement for testing against the actual device. Whenever possible, you should test your application on a real device client.

Selelct the Virtual Radio deployment option and click Deploy. This will start the process of loading the emulator and the application. While deploying the application it first loads up System_SR_ENU.phone.cab, you need to watch the emulator screen and click the left soft key button to install it. It is a file used for development purposes; it contains string resources useful for debugging applications. Do not include it in your final application package.

Thanks for your registration, follow us on our social networks to keep up-to-date