The demos
so far showed the 2-tier setup where the
client application has direct connection
to the database. With all the hype about
service oriented architecture stuff, it
is hard to ignore the mid-tier scenario
any longer than that. So here it is, in
this demo I show you how to extend
2-tier synchronization application to
become N-tier one.
In N-Tier
setup, the server sync provider runs one
the server node, while the sync agent
and client provider reside on the
client. Since the agent is located on
the client, the client application runs
the show. This is the typical setup,
however, there is no technical reason
not to locate the agent on the server
and implement some sort of a server
driven push sync. Although, this is not
what the framework is optimized for.
Two steps
are need to turn our 2-tier application
developed in 'demo II' to n-tier
application:
Step 1:
Expose ServerSyncProvider Interface as
Web Service
This is
really simple step. The
ServerSyncProvider interface has only
four methods, again only four methods.
That's is not a sheer luck! To expose
those four method as web methods, we
need a simple wrapper as shown in the
code below:
public
class
Service : System.Web.Services.WebService
{
private
DbServerSyncProvider _serverProvider;
public
Service ()
{
///
Same code as in demo II Sychronize
button code
}
///
Access server sync parameters
[WebMethod]
public
SyncServerInfo GetServerInfo()
{
return
_serverProvider.GetServerInfo();
}
///
Access table schema in DataSet form
[WebMethod]
public
SyncSchema GetSchema(Collection<string>
tableNames)
{
return
_serverProvider.GetSchema(tableNames);
}
///
Enumerate group changes
[WebMethod]
public
SyncContext
GetChanges(SyncGroupMetadata
groupMetadata, SyncSession
syncSession)
{
return
_serverProvider.GetChanges(groupMetadata,
syncSession);
}
///
Apply group changes
[WebMethod]
public
SyncContext
ApplyChanges(SyncGroupMetadata
groupMetadata, DataSet dataSet,
SyncSession syncSession)
{
return
_serverProvider.ApplyChanges(groupMetadata,
dataSet, syncSession);
}
}
Our simple
wrapper just relay the calls to the
ServerSyncProvider instance. Take a look
at service.cs file for the code of the
constructor to this type. You will find
it familiar since it is the same code
for the sync adapters we had in the
previous demo. With this, the server
side is ready to serve clients. Let's
switch gears to client side.
Step 2: Expose the Web Service Proxy as
ServerSyncProvider Interface
On the
client, you know what to do. Reference
the web service we just created in the
client project. I will call the web
reference, SyncWebService:

In its raw
form, the web reference inherits from
SoapHttpClientProtocol. The SyncAgent
expects a ServerSyncProvider instance.
Yes, we need another wrapper class to
relay the same four methods to the web
service proxy. If you are interested in
seeing yet another wrapper class, check
out the ServerSyncProviderProxy.cs for
the code.
The rest
is detail at this point. Just pass the
proxy type to the sync agent and you are
done.
Compiling
the client project will generate few
errors due to type sharing issues. The
steps to install the web service below
should help you resolve these issues.
That was
easy, wasn't it? ready for another demo?
Install OfflineAppDemo
Application Steps:
-
Fire SQL
server and
load
demo.sql
file
-
Execute the
script
until the
"test
sample"
marker
-
load
server_procs.sql
file and
execute it
to create
sync stored
procedures
on the
server
-
Install
SyncWebService
(see steps
below)
-
Load VS
solution (OfflineAppDemo-WebService
Project)
-
You are
ready to go
Install Sync Web Service
Steps:
-
Copy
SyncWebService
directory to
c:\interpub\wwwroot
-
From IIS
management
console,
setup the
SyncWebService
virtual
directory as
web
application
and set
Application
Pool to
ASP.NET
2.0
-
Give network
service
account
read\write
access
to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary
ASP.NET
Files
-
Add web
reference to
the project
and give it
a name
SyncWebServiceProxy
-
Edit the
Reference.cs
manually and
add
namespace
Microsoft.Synchronization.Data.
Also remove
code for
types that
are already
defined in
Microsoft.Synchronization.Data.dll as
the sample
reference.cs file
shows
-
Add new
login to SQL
Server for
Network
Service and
give it
dbowner
access to
the pub
database
Version
1.2 [C#] :
Download Now
|