An alternative to using webservices is to use sql replication. The Subscription Manager application block provides a simple interface with which to manage sql replication between a sql mobile database and a sql server via a web publication (class list below).
The following example illustrates how you can create a DatabaseService to connect to a SQL Mobile database. A SubscriptionManager is created and a SubscriptionParameters object is created to hold the properties of the publication to connect to. The Synchronize method invokes the synchronisation process – this can be wired up to the Connection Manager to automatically synchronize when a network connection becomes available.
‘Create the database service – ie which database
Dim ds As DatabaseService = New SqlDatabaseService(“DataSource=””AWReplication.sdf””;”)
Dim credentials As ISubscriptionCredentialService = New SubscriptionCredentialService()
Dim subs As New SubscriptionManager(ds, credentials)
Dim subParams As New SubscriptionParamaters()
subParams.Filter = “Mr.”
subParams.InternetUrl = “http://192.168.1.100/AWSampleWWW/sqlcesa30.dll”
subParams.Publication = “AWSample”
subParams.Publisher = “serverName”
subParams.PublisherDatabase = “AdventureWorks”
subParams.Subscriber = “CustomerListSubscription”
In this example an instance is created of the SubscriptionCredentialService. This is a class that we have created (that implements ISubscriptionCredentialService). In the future this will hopefully be merged with the CredentialService block.
Public Class SubscriptionCredentialService
Public Function FindCredentials(ByVal subscription As Subscription) As SubscriptionCredentials Implements ISubscriptionCredentialService.FindCredentials
Dim cred As SubscriptionCredentials = New SubscriptionCredentials()
cred.PublisherSecurityMode = SecurityType.NTAuthentication