|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Contents
IntroductionI 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 RequirementSoftware requirement for the Pocket PC are:
Hardware considerations:
Sample Code AnalysisThe 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 ServiceUsing 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 InterestThe 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:
Other Useful Links on Pocket PC
HistoryCreated date -22 March, 2005.
|
||||||||||||||||||||||