5,696,038 members and growing! (13,023 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Howto     Intermediate

Pocket PC Calling Dynamic Web Service

By latha vallinayagam

An article on Pocket PC connecting to a dynamic web service.
C#, Windows, .NET CF, .NET 1.1, .NET, MobileVisual Studio, VS.NET2003, Dev

Posted: 28 Mar 2005
Updated: 28 Mar 2005
Views: 48,619
Bookmarked: 25 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 1.86 Rating: 2.06 out of 5
3 votes, 37.5%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 25.0%
4
3 votes, 37.5%
5

Sample Input PocketPC

Sample OutPut PocketPC

Contents

Introduction

I started off with my project in Pocket PC knowing nothing. But many articles in The Code Project and other URLs I have given below gave me a quick start. But dynamic URL was the biggest pain of all. So I wanted to share my piece of experience with everyone.

Software Requirement

Software requirement for the Pocket PC are:

  • Microsoft ActiveSync

    This is the tool connecting the workstation and the Pocket PC, the first tool to be installed to work with the Pocket PC.

  • MDAC 2.7
  • Microsoft Compact Framework.

    This framework will be used to put all the libraries required for the Pocket PC to support a .NET application.

Hardware considerations:

  • The Pocket PC will require a serial port to connect to the workstation.

Sample Code Analysis

The application I have done here will create an XML string and transfer that XML string to a web service, the web service takes care of opening the XML string and displaying it in the next screen. This application with get the strings from the textbox provided and combine that to an XML formatted data. These XML data are received from the web service side and shown in the textbox.

//

// code for the data tansfer

//

private void btnTransfer_Click(object sender, System.EventArgs e)
{
    try
    {
        StringBuilder sText = new StringBuilder();
        sText.Append("<DATA>");
        if(txtstr1.Text != "")
        {
            sText.Append("<string1>");
            sText.Append(txtstr1.Text);
            sText.Append("</string1>");
        }
        else if(txtstr2.Text != "")
        {
            sText.Append("<string2>");
            sText.Append(txtstr2.Text);
            sText.Append("</string2>");
        }

        sText.Append("</DATA>");
        Homer.dataTransfer xmlTransfer = new Homer.dataTransfer();
        xmlTransfer.Url = GetWebServiceUrl() ;
        string strResponse = xmlTransfer.DataTransfer(sText.ToString());
        MessageBox.Show("the message was " + strResponse);
    }
    catch(Exception exc)
    {
        lblResponse.Text = exc.Message;
    }
}
//code for receving message from web service

Following is the code for calling the dynamic URL. The way to call the web service dynamically is by creating an INI file, for e.g., webserviceUrl.ini as in my example. The content of the file is as follows. This file should be placed in the application folder in the Pocket PC. This application cannot be tried with the simulator. You can always work with the static Web service URL in the simulator.

//content of the webservice ini file

<?xml version="1.0" encoding="utf-8" ?>
<appConfig>
 <webServiceUrl>
   http://your_server_name_goes_here/SampleService/Service1.asmx
 </webServiceUrl>
</appConfig>

The web service INI file is opened from the function below and the web reference is taken from the INI file.

Dynamic XML Web Service

Using a web service is simpler in the mobile application, but to make it dynamic was one of a task. Since the Pocket PC has to be tested in various scenarios and then modified for the live server, the dynamic web service is not the same for the mobile application as the web application. The code below will help you in setting up the dynamic web service URL for the application.

//

// Code for calling the dynamic URL

//

private string GetWebServiceUrl()
{
    string Apppath = null;
    Apppath = System.IO.Path.GetDirectoryName( 
              System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
    string iniFile = Apppath + @"\WebServiceUrl.ini";
    FileStream xmlStream = new FileStream(iniFile, FileMode.Open);
    XmlTextReader xmlReader = new XmlTextReader(xmlStream);

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlReader);

    xmlReader = null;
    xmlStream.Close();
    XmlNode xmlRoot = xmlDoc.DocumentElement;

    string Url = xmlRoot.ChildNodes.Item(0).ChildNodes.Item(0).Value;
    xmlDoc = null;

    return Url;
}

Points of Interest

The above should help anyone start off smoothly with the Pocket PC application. Some final words of caution and things that I faced while working with Pocket PC:

  • When we work with the Pocket PC application forms, the instance will still run even when we close the form. So to eliminate the problem, I had to make the minimize button to false, so when we close the form in the Pocket PC, it removes the instance of the application.
  • When a developer is not able to run the application due to an error message like the application is already running an instance, the following links can help you eliminate the issue.

Other Useful Links on Pocket PC

History

Created date -22 March, 2005.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

latha vallinayagam



Occupation: Web Developer
Location: United States United States

Other popular Mobile Development articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
QuestionPocket PCmemberMember 41859470:40 7 May '08  
GeneralHow to call webservice from pocketpc application using win32?memberpraveen_kush4:50 12 Oct '07  
GeneralEven more WTFsmembernsimeonov22:04 8 Oct '06  
GeneralWTFmembernsimeonov19:13 8 Oct '06  
GeneralDoesn't worksmemberMiguel Bocanegra10:10 15 Sep '06  
GeneralError while reading XML Web servicesmemberDotnetblog23:38 27 Jan '06  
GeneralIn the Data Transfer Function we meet error.memberYMVPR16:47 15 Nov '05  
GeneralRe: In the Data Transfer Function we meet error.memberEdgar T6:44 10 Feb '06  
QuestionRe: In the Data Transfer Function we meet error.memberfizous23:00 20 Mar '06  
GeneralReally good work but I've got a deep question for youmemberlonifasiko1:12 22 Jul '05  
GeneralHow do I get the service startedmemberChromeDomeSA20:51 26 May '05  
GeneralRe: How do I get the service startedmemberChromeDomeSA15:14 1 Jun '05  
GeneralHow To Change this INI file DynamicallymemberChandra Murali2:13 11 Apr '05  
GeneralRe: How To Change this INI file Dynamicallymemberlatha vallinayagam4:42 11 Apr '05  
GeneralRe: How To Change this INI file DynamicallymemberVenkat Polisetti10:16 12 Apr '05  
GeneralRe: How To Change this INI file DynamicallymemberChandra Murali2:02 13 Apr '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Mar 2005
Editor: Smitha Vijayan
Copyright 2005 by latha vallinayagam
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project