.NET Components for Mobility

Peter Foot

Microsoft Device Application Development MVP

October 2007 - Posts

  • Networking Session at Tech Ed Developers 2007

    The schedule for Tech Ed is now set. Now, I can't compete with Daniel on quantity, but hopefully can equal him on quality. However this requires help from you - I am hosting an interactive session and so you can help steer the direction of the session (within the scope of networking and Windows Mobile of course). If you have any particular topics that you would like to see addressed then please let me know via the comments on this post, or via email (there is a contact link on this page). I'm going to bring with me a selection of code samples and some demos including some interactive Bluetooth content (so bring your Windows Mobile (or other Bluetooth equipped) devices along. Here are the details:-

    Tue Nov 6 09:00 - 10:15 Room 131 MED01-IS An Open Discussion of Networking Technologies within Windows Mobile

    I look forward to seeing you there!

    Posted Oct 16 2007, 11:08 AM by Peter Foot
    Filed under:
  • How To: Use the WebRequestMethods class

    Networking In The Hand introduces a repository for all the various method types for FTP and HTTP operations. While the common ones are easy to remember ("GET","POST" etc) many others are not, and so this class (like its desktop equivalent) provides a central place to refer to them, without dotting your code with hard-coded strings. WebRequestMethods contains two static classes - Ftp and Http which as the name suggests contain the two sets of operations. Here we find one used in the previous sample:-

    InTheHand.Net.WebRequestMethods.Ftp.GetDateTimestamp

    As with all the functionality in the namespace, you'll find the full details in the online documentation library.

    >
    Posted Oct 09 2007, 11:06 AM by Peter Foot
    Filed under:
  • How To: Use the FtpWebRequest

    Networking In The Hand includes a full desktop-compatible implementation of the FtpWebRequest class. This plugs into the WebRequest class so that calling WebRequest.Create() with an FTP Uri will create an object of type FtpWebRequest. Because FTP support isn't built into the Compact Framework you have to register the class with this prefix using the the following code (only required once in your code):-

    InTheHand.Net.FtpWebRequest.RegisterPrefix();

    We have already looked at performing simple operations with the WebClient class. for more complex FTP operations you can use the FtpWebRequest directly. For example retrieving the modification date of a specific file:-

    FtpWebRequest requestDate = (FtpWebRequest)FtpWebRequest.Create(requestUri);
    requestDate.Method = WebRequestMethods.Ftp.GetDateTimestamp;
    if (wc.Credentials != null)
    {
       requestDate.Credentials = wc.Credentials;
    }
    FtpWebResponse responseDate = null;

    responseDate = (FtpWebResponse)requestDate.GetResponse();

    if (responseDate != null)
    {
       MessageBox.Show(responseDate.LastModified.ToString());
       responseDate.Close();
    }

    Posted Oct 04 2007, 11:00 AM by Peter Foot
    Filed under:
  • How To: Use the WebClient

    Networking In The Hand includes the WebClient class which is a helper class which makes it easier to do uploading and downloading of data using HTTP and FTP transports. For example rather than creating an HttpWebRequest, setting a number of properties, getting the response and reading the response stream and copying the data into a file, why not use DownloadFile to perform a single operation to write the data from a specific Uri to a local file:-

    WebClient wc = new WebClient();
    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
       wc.DownloadFile(uriTarget, saveFileDialog1.FileName);
    }

    Additional methods provide the ability to download a string, and download a byte array containing the data. There are a similar set of operations for uploading:-

    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
       wc.UploadFile(uriDestination, openFileDialog1.FileName);
    }

    Not only does this work with the HTTP transport, but also with the FTP support which is also part of the library - the only difference is the Uri that you pass in. If your site requires a username/password you can set the Credentials property of the WebClient once and they will be used for all subsequent operations.

    Posted Oct 02 2007, 10:49 AM by Peter Foot
    Filed under:
  • Fix: SMS Interception on T-Mobile Dash

    A number of customers have been reporting issues with SMS interception on the T-Mobile Dash handset. On these devices the SMS interception does not work through either the Microsoft or In The Hand class libraries. This is specific to the T-Mobile ROM as other branded versions of the same device, such as the HTC S620, do not have the problem. The culprit is a badly behaved IMessageFilter implementation which stops the standard interceptor from working. You can fix this issue by removing the entry from the registry. Take a look at this registry key:-

    HKEY_LOCAL_MACHINE\Software\Microsoft/Software/Inbox/Svc/Sms/Rules

    In here you'll find 2 entries by default on Windows Mobile 5.0:-

    {1000BC1C-F4A3-4210-B197-4AEBF2CEE6F5}

    {77990A0E-60B8-4103-B9AF-17157E4274FD}

    If you find additional entries here try deleting them (make a backup first so that you can restore if necessary) then reset the phone. This should allow the normal SMS interception mechanism to work again.

    On Windows Mobile 6 the above registry key is not present by default, therefore the standard SMS interception will work without any additional rules registered.

  • How To: Use the Ping class

    Networking In The Hand includes the Ping class (In the InTheHand.Net.NetworkInformation namespace). The component allows you to determine if a network path to a particular host is available and whether the host is responding. It doesn't guarantee that a particular service is running on the server (HTTP, FTP etc). You can perform a Ping in a couple of lines of code, the class has been designed to be an exact subset of the equivalent class in the full .NET framework. The following is an example of the simplest ping request using a default payload and timeout settings.

    InTheHand.Net.NetworkInformation.Ping p = new InTheHand.Net.NetworkInformation.Ping();
    InTheHand.Net.NetworkInformation.PingReply reply = p.Send("www.google.com");

    if (reply.Status == IPStatus.Success)
    {
       string message = string.Format("Address: {0}\r\nRoundTrip time: {1}\r\nTime to live: {2}\r\nDon't fragment: {3}\r\nBuffer size: {0}",
          reply.Address.ToString(),
          reply.RoundtripTime,
          reply.Options.Ttl,
          reply.Options.DontFragment,
          reply.Buffer.Length);

       MessageBox.Show(message, "Ping");
    }
    else
    {
       MessageBox.Show(reply.Status.ToString(), "Ping");
    }
    >

    The class allows you to further customise the request. You can specify your own data payload for example, or set a different timeout value (the default is 5 seconds).

    Posted Oct 01 2007, 10:40 AM by Peter Foot
    Filed under:
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.