Deepthi's profileWin with Win MobilePhotosBlogListsMore Tools Help

Deepthi Rao

Occupation
No list items have been added yet.

Win with Win Mobile

January 16

Approaches to data synchronization on windows mobile-Using Web Synchroniazation over sql server merge replicaiton

 

In part 1 of this post, I discussed about using the Disconnected Service Agent application block for data synchronization. This entry discusses the second method, which is web synchronization using merge replication.

 

 

Web Synchronization over Sql Server Merge Replication

 

This approach makes use of the merge replication features provided by Sql Server 2005 and Sql Server Mobile, extending it over http using IIS.

 

 

Some concepts related to merge replication:

Publisher

The Publisher is a database instance that makes data available to other locations through replication.

 

Distributor

The Distributor is a database instance that acts as a store for replication specific data associated with one or more Publishers. Each Publisher is associated with a single database (known as a distribution database) at the Distributor.

 

Subscribers

A Subscriber is a database instance that receives replicated data. A Subscriber can receive data from multiple Publishers and publications.

 

Publication

A publication is a collection of one or more articles from one database.

 

Subscription

A subscription is a request for a copy of a publication to be delivered to a Subscriber. The subscription defines what publication will be received, where, and when.

 

Web synchronization for merge replication provides the ability to replicate data using the HTTPS protocol and is well suited to the following scenarios:

 

  • Synchronizing data from mobile users over the Internet.

 

  • Synchronizing data between Microsoft SQL Server databases across a corporate firewall.

 

 

 

Web synchronization is designed for synchronizing data with laptops, handheld devices, and other clients. It is not intended for high volume server to server applications.

 

To use Web synchronization for replication, you must perform the following steps.

 

  1. Configure a publication to use Web synchronization.

 

  1. Configure the Microsoft Internet Information Services (IIS) server used to synchronize subscriptions. IIS versions 5.0 and 6.0 are supported.

 

  1. Configure the publication and subscription to use Web synchronization.

 

 

Thus we can see that we can use the web synchronization feature of Sql Server when we need to synchronize between a sql server 2005 mobile and sql server 2005. For a more platform–neutral approach, we can use the disconnected web services approach using the Disconnected Services Agent.

Approaches to data synchronization on windows mobile-Using Disconnected Web services

 

Approaches to data synchronization on windows mobile

 

The growing capabilities of mobile devices such as the Pocket PC, and their increasingly

widespread usage within the commercial world, provide an opportunity for business

solutions to broaden their spread to include remote and mobile workers. All of these may require access to the corporate IT system - in either a connected or a disconnected scenario, and data synchronization between a mobile device and the server is an essential component of such systems.

 

This blog entry (in two parts ) explains in brief two approaches to tackle the data synchronization problem:

 

1. Disconnected web services (using Disconnected Service Agent from Mobile Client Software Factory)

 

2. Sql Server Merge Replication over Http.

  

 

  1. Disconnected Web services

 

In this method, we make use of the Disconnected Service Agent Application Block provided by the Mobile Client Software Factory (which can be downloaded from). The Disconnected Service Agent Block (DSAB) provides features for storing offline Web Service requests, and executing them when connectivity is available

 

There are two distinct sections in the Disconnected Service Agent Block:

 

1. A subsystem that allows developers to invoke disconnected Web Services. The Service Agent queues requests and keeps track of the asynchronous callbacks that the application expects to receive when the Web Service responds.

 

2. A Dispatcher that determines exactly when to dispatch each call to a Web

Service, depending on connectivity conditions, pricing policies, and configuration

settings. When the correct conditions occur, the dispatcher makes the request,

using the appropriate credentials and addresses for the endpoint.

 

The Disconnected Service Agent Block exposes several core classes that you work

with when using the services provided by this block:

 

• The RequestManager class implements and manages the request queues, and

uses the services of the WebServiceRequestDispatcher class to dispatch these

requests. It stores the queues of pending and failed requests in the SQL Server

Mobile Edition database on the device using the DatabaseRequestQueue class,

or a custom implementation of the IRequestQueue interface.

 

• The Request class provides facilities for creating Web Service requests, adding

the arguments or parameters required by the Web Service method, specifying

the endpoint for delivery of the request, and setting the properties for handling

and delivery of the request.

 

• The ConnectionMonitorAdapter class provides information about the

connection used by the request, such as the price and network details, and

raises events when status of the connection changes. It sits between the RequestManager and theConnectionMonitor, acting as broker for request and the events raised by ConnectionMonitor.

 

December 22

Managed Wrapper for Installing MSMQ on Pocket PC

Msmq component is bundled with the OS. We need to install it as a separate cab file from the following link :
 
 
In my blog post titled 'Message Queues in .net CF' ,I mentioned the steps that need to be followed to install the msmq cab file manually.
 
Here's a wrapper class that will do the same through code. What I have done is call the processes that are required to be called to install,register,start and stop msmq. Also we can enable srmp and binary protocols through this wrapper.
 

using System;

using

System.Diagnostics;

using

System.IO;

using

System.Runtime.InteropServices;

namespace MessagingQueueWrapper

{

public class MessagingQueueWrapperClass

{

[

DllImport("CoreDll.dll")]

private extern static

Int32 GetLastError();

[

DllImport("CoreDll.dll")]

private extern static

Int32 CloseHandle(IntPtr hProcess);

[

DllImport("CoreDll.dll")]

private extern static

IntPtr ActivateDevice(

string lpszDevKey,

Int32 dwClientInfo);

//Execute commands on the MSMQAdm.exe utility

public static bool ExecuteMSMQAdm(String CmdLine)

{

Process prc = Process.Start(@"\windows\msmqadm.exe", CmdLine);

if (prc == null)

throw new ApplicationException("Process already running");

prc.WaitForExit();

if (prc.ExitCode != 0)

return false;

else

return true;

}

//This is the MSMQAdm.exe utility we’ll be using

private const String MSMQ_ADM = @"\windows\msmqadm.exe";

private const String MSMQ_DRIVER_REG = @"Drivers\BuiltIn\MSMQD";

private const string MsmqLogFilePath = @"\windows\MsmqLogFile";

public enum MsmqErrorCodes

{

Success,

RegisterInstallFailed,

RegisterFailed,

EnableBinaryFailed,

EnableSrmpFailed,

StartFailed,

StatusFailed

};

 

public static MsmqErrorCodes StartMSMQ()

{

//Check status of MSMQ (is it installed and running yet?

if (!(ExecuteMSMQAdm("status")))

{

//Deletes the MSMQ registry key and store directory.

//All messages are lost.

ExecuteMSMQAdm(

"register cleanup");

//Installs MSMQ as device drivers.

if (!ExecuteMSMQAdm("register install"))

{

return MsmqErrorCodes.RegisterInstallFailed;

}

//Creates the MSMQ Configuration in Registry

if (!ExecuteMSMQAdm("register"))

{

return MsmqErrorCodes.RegisterFailed;

}

//Enables the native MSMQ protocol

if (!ExecuteMSMQAdm("enable binary"))

{

return MsmqErrorCodes.EnableBinaryFailed;

}

//Starts the MSMQ service

if (!ExecuteMSMQAdm("start"))

{

//This is one additional step that is needed for PocketPCs

//The Device Drivers have to be loaded before the service

//can be started

//ActivateDevice will load the device drivers

IntPtr handle = ActivateDevice(MSMQ_DRIVER_REG, 0);

CloseHandle(handle);

//Let us check if MSMQ is running

if (!ExecuteMSMQAdm("status"))

{

return MsmqErrorCodes.StatusFailed;

}

return MsmqErrorCodes.StartFailed;

}

return MsmqErrorCodes.Success;

}

else

return MsmqErrorCodes.Success;

}

public static MsmqErrorCodes EnableSrmp()

{

//Check status of MSMQ (is it installed and running yet?

if (!(ExecuteMSMQAdm("status")))

{

MessagingQueueWrapper.

MessagingQueueWrapperClass.StartMSMQ();

}

//Starts the MSMQ service

ExecuteMSMQAdm(

"stop");

//Enables the native MSMQ protocol

if (!ExecuteMSMQAdm("enable srmp"))

{

return MsmqErrorCodes.EnableSrmpFailed;

}

if (!ExecuteMSMQAdm("start"))

{

return MsmqErrorCodes.StartFailed;

}

else

return MsmqErrorCodes.Success;

}

}

}

 

How to use :

 Create a class library and copy-paste this code in that,

build it and add a reference to this dll (MessageQueueWrapper) in ur project.

In the FormLoad method, you can call the install and enable methods like this:

if

(MessagingQueueWrapper.MessagingQueueWrapperClass.StartMSMQ() == MessagingQueueWrapper.MessagingQueueWrapperClass.MsmqErrorCodes.Success)

MessageBox.Show("Success in installing");

if (MessagingQueueWrapper.MessagingQueueWrapperClass.EnableSrmp() == MessagingQueueWrapper.MessagingQueueWrapperClass.MsmqErrorCodes.Success)

MessageBox.Show("Success in enabling srmp");

And lo ! MSMQ is installed on ur device !

Hope that helps :)..I spent quite a few days trying to figure out how to enable srmp manually...this should save us all the trouble :).

 

 

December 18

Obtaining the Device/Emulator's IP Address

 
 

I was trying to figure out how to obtain the IP address of my device /emulator once its cradled. Finally I wrote a small app (if u can call 4 lines of code an application :) ), and this displays the device IP in a messagebox.

 
 Heres the code :
 

try // Put this in FormLoad()

 

{

IPHostEntry IpEntry = Dns.Resolve(Dns.GetHostName());

foreach(IPAddress IpAddr in IpEntry .AddressList)

{

MessageBox.Show(IpAddr.ToString());

}

}

catch(Exception ex)

{

MessageBox.Show(String.Format("Exception Caught: {0}\n{1}", ex.GetType().ToString(), ex.Message));

}

PS.: You might get a warning saying Dns.GetHostName() is obsolete-but never mind :)-the code still works !

 

December 07

MSMQ over HTTP

The coolest features of MSMQ 3.0 is the ability to send messages over HTTP - right through firewalls. For this to be possible, we need to have the MSMQ over HTTP component installed. (under Add/Remove Programs->Windows Components->Application Server->Message Queueing->).
 
If you have it installed, you will see an IIS application with the name 'msmq', and it will have nothing in it.
 
SOAP Reliable Messaging Protocol (SRMP), an XML-based messaging protocol, has been developed for delivering high Quality of Service (QoS) messages. The direct, public, and private format names of administration and response queues can be included in messages sent over HTTP transport. Similarly, the names of administration and response queues in HTTP format can be included in messages sent over ordinary (non-HTTP) transport.
 
Destination queues for HTTP messages are opened using direct format names that include the URL address of the target computer, the virtual directory name, and the queue name separated by slashes. The default virtual directory name is msmq, but Message Queuing can be configured by IIS to use a different virtual directory. A direct format name containing HTTPS as the protocol name invokes a secure HTTP transport through a Secure Sockets Layer (SSL) connection.
 
Now to send my message over MSMQ using http, what I did was create a message queue with the following direct format name :

@"FormatName:DIRECT=http://172.30.189.xxx/msmq/Private$/myqueue" with my machine's ip address.

That does the trick :)..more on msmq over http in .net cf in the next post. cya !

 

 
 
 
There are no photo albums.
No list items have been added yet.