Web Service On Windows Mobile

Yes.

I’ve seen many people, who are facing issues while accessing Web Service on Windows Mobile enabled devices. Although there are lot of posts on blogs and forums, sometimes, it doesn’t work. Why? Because there are lot of issues.

Let’s see all those issues and solve them. I hope that readers of this blog are aware of creating Web Services in C# / VB.NET using Visual Studio 2005 or 2008.

If not, lets create a simple Hello World web service i.e. a web method, when called will return a Hello World string. By default, when you create any web service in Visual Studio it gives you “Hello World” method as a web method which can be consumed (or used) as web service.

Now, lets see how we can access this web service in Windows Mobile based applications.

1. Create a Windows Mobile based Windows Forms Application

2. Add a Web Reference to your web-service. Now, here is the glitch. While adding a reference it uses your system as a localhost (in some cases port no attached) but when you deploy your application on Windows Mobile, actually your web-service is still running on your development machine and not on your device. Hence, change this localhost with your development machine name OR machine name on which your web service is hosted. Don’t use IP address. Why? Because, when you attach your mobile device to the machine, using DHCP it gets automatic IP address. So, don’t set any IP address rather use machine name.

3. Now, create a proxy class and use that web service in your application.

4. To test the application, run it in emulator or on device. Now, if you’re running your application on real physical device then it should work properly. But, if you’re running it on emulator, then make sure that…

a. In ActiveSync -> File -> Connection Settings, you have allowed DMA connections.

b. When Device Emulator is running, in Device Emulator Manager, Cradle your device. That means, it’ll connect your device emulator to your machine.

This ways you should be able to consume web service hosted on your machine onto your mobile device (whether real-physical device OR emulator).

I hope, this clarifies and solves most of the issues.

Soon, I will create a Screen Cast and host it on my blog.

Namaste…..

Mayur Tendulkar | Microsoft India

Heroes Happen Here Launch Presentations

Hi,

As part of Microsoft Heroes Happen Here Launch – we launched Microsoft Windows Server 2008, Microsoft Visual Studio 2008 and Microsoft SQL Server 2008 at various Microsoft Partner locations.

For that reason, I used PowerPoint presentations that I would like to share with all of us. Please click on the below link which will redirect you to my shared MSN SkyDrive Folder.

Also, if you want to try out your hands on latest Microsoft Products, then you can download OR order the trial versions from following links. Click on the product name to go to the Product home page.

Microsoft Windows Server 2008

Microsoft Visual Studio 2008

Microsoft SQL Server 2008 (CTP)

http://cid-96142e9b7756161d.skydrive.live.com/embedrowdetail.aspx/Campus%20Launch

Regards

Mayur Tendulkar | Microsoft India

Language Enhancements In C# 3.0 and VB 9

There are so many new features added as Language Enhancement for C# 3.0 and VB 9.0 in Visual Studio 2008 (along with .NET Framework 3.5). Here, I’m compiling a quick list of important ones and will share some resources from where you can learn more about the same.

  1. Local Type Inference
    Visual Studio uses type inference to determine the data types of local variables declared without data-type. The compiler infers the type of the variable from the type of the initialization expression. This enables you to declare variables without explicitly stating a type, as shown in the following example.
    String str1 = "Mayur Tendulkar";
    var str2 = "Mayur Tendulkar";

    For more information visit following links:
    http://msdn2.microsoft.com/en-us/library/bb384937.aspx

  2. Object and Collection Initializers
    Object and Collection Initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor
    class Person
    {
    String Name { get; set; }
    String EMailID { get; set; }
    }
    class PersonImplementation
    {
    static void CreatePerson()
    {
    //Object Initializer Used
    Person p = new Person { Name = "Mayur Tendulkar", EMailID = "mayur.tendulkar@gmail.com" };
    //Collection Initializer (with Object Initializer) Used
    List per = new List
    {
    new Person() { Name = "ABC", EMailID = "abc@abc.com"},
    new Person() { Name = "XYZ", EMailID = "xyz@xyz.com"}
    };
    }
    }

    For more information, visit following link:
    http://msdn2.microsoft.com/en-us/library/bb384062.aspx

  3. Anonymous Types
    Anonymous types enable you to create objects without writing a class definition for the data type. Instead, the compiler generates a class for you. The class has no usable name, inherits directly from Object, and contains the properties you specify in declaring the object. Because the name of the data type is not specified, it is referred to as an anonymous type.
    var Student = new { Name = "Mayur", LastName = "Tendulkar"};

    For more information, visit following link:
    http://msdn2.microsoft.com/en-us/library/bb397696.aspx

  4. Auto Implemented Properties
    Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property’s get and set accessors.
    class Female
    {
    string Name { get; set; }
    int Age { private get; set; } //Write only
    int Mobile { get; private set; } //Read only
    }

    For more information visit following link:
    http://msdn2.microsoft.com/en-us/library/bb384054.aspx

  5. Partial Method
    Partial methods enable the implementer of one part of a class to define a method, similar to an event. The implementer of the other part of the class can decide whether to implement the method or not. If the method is not implemented, then the compiler removes the method signature and all calls to the method. Therefore, any code in the partial class can freely use a partial method, even if the implementation is not supplied. No compile-time or run-time errors will result if the method is called but not implemented.
    // Definition in file1.cs
    partial void onNameChanged();

    // Implementation in file2.cs
    partial void onNameChanged()
    {
    // method body
    }

    For more information visit following link:
    http://msdn2.microsoft.com/en-us/library/wa80x488.aspx

In this blog post we seen 5 new concepts that are included in VS2008 (.NET 3.5) and in next post, we’ll see some more of them.