Friday, January 9, 2009

Microsoft ADO.NET Synchronization Architecture






Overview
Applications are increasingly being used on mobile clients, such as portable computers and devices. Because these mobile clients do not have a consistent or reliable network connection to a central server, it is important for these applications to work against a local copy of data on the client. Equally important is the need to synchronize the local copy of the data with a central server when a network connection is available. Modeled after the ADO.NET data access APIs, the Synchronization Services API provides an intuitive way to synchronize data. Synchronization Services makes building applications for occasionally connected environments a logical extension of building applications in which you can depend on a consistent network connection.
Architecture
Microsoft Synchronization Services for ADO.NET is a set of DLLs that provides a compassable API. Depending on the architecture and requirements of an application, you can use all or only some of the components that are provided. Synchronization Services enables synchronization between a SQL Server Compact 3.5 client database and a server database or any other data source, such as a service that provides stock quotes in XML. For synchronizing two databases, Synchronization Services supports two-tier and N-tier architectures that use any server database for which an ADO.NET provider is available. For synchronizing between a client database and other types of data sources, Synchronization Services supports a service-based architecture. This architecture requires more application code than two-tier and N-tier architectures; however, it does not require a developer to take a different approach to synchronization.
The following illustrations show the components that are involved in two-tier, N-tier, and service-based architectures. Each illustration shows a single client, but there are frequently multiple clients that synchronize with a single server. Synchronization Services uses a hub-and-spoke model. Synchronization is always initiated by the client. All changes from each client are synchronized with the server before the changes are sent from the server to other clients. (These are clients that do not exchange changes directly with one another.)







Synchronization Services provides snapshot, download-only, upload-only, and bidirectional synchronization:







  • Snapshot and download-only synchronization are typically used to store and update reference data, such as a product list, on a client. Data changes that are made at the server are downloaded to the client database during synchronization. Snapshot synchronization completely refreshes data every time that the client is synchronized. This is appropriate when you do not want to track incremental changes or the server cannot do so. Download-only synchronization downloads only the incremental changes that have occurred since the previous synchronization.




  • Upload-only synchronization is typically used to insert data, such as a sales order, on a client. Inserts and other changes to data that are made in the client database are uploaded to the server during synchronization.




  • Bidirectional synchronization is typically used for data, such as customer contact information, that can be updated at the client and server. Any conflicting changes must be handled during synchronization.




  • The Synchronization Services architecture is asymmetric: This means that change-tracking is built into the client database, but you must track changes in the server data store if you want incremental changes to be downloaded. For more information about the types of synchronization


The components in the architecture illustrations include the client and server databases and a set of classes from the Synchronization Services API. The N-tier and service-based architectures also include Web Service and Transport components that you must write.



Two – Tier Architecture








Except for the two databases, all items in the illustration correspond to Synchronization Services classes. These classes are contained in the following DLLs:







  • Microsoft.Synchronization.Data.dll contains Synchronization Agent, Synchronization Tables, and Synchronization Groups.




  • Microsoft. Synchronization.Data.SqlServerCe.dll contains the Client Synchronization Provider.




  • Microsoft. Synchronization.Data.Server.dll contains the Server Synchronization Provider and Synchronization Adapters.




  • All the above dlls depend on System.Data.dll and System.dll with related .NET Framework version.Microsoft.Synchronization.Data.SqlServerCe.dll also depend of System.Data.SqlServerCe.dll from SQL Server Compact 3.5 for Two tire applications, all Synchronization Service dlls reside on the client. For N-tires applications same dlls reside on computer that provides a Synchronization Services.




  • N-Tier Architecture




The second illustration shows N-tier architecture. This requires a proxy, a service, and a transport mechanism to communicate between the client database and the server database. This architecture is more common than two-tier architecture, because N-tier architecture does not require a direct connection between the client and server databases.










Service-based Architecture





The third illustration shows a service-based architecture. This architecture includes a client database, but does not include a server database or the corresponding Server Synchronization Provider and Synchronization Adapters. To use this kind of architecture, an application must be able to communicate to the Synchronization Agent through a custom proxy and custom service. These must provide the same functionality that the Server Synchronization Provider and Synchronization Adapters usually provide, such as retrieving changes to synchronize.















Pre – requirement





































































A Synchronized Service Application










You can easily write your first application for synchronization after reading sample of code. Before started make sure that following items are installed on your computer


















  • Synchronization Service












    • The application required Microosft.Synchronization.Data.dll, Micorosoft.Synchronization.Data.SQLServerCe.dll








  • SQL Server Compact 3.5












    • The Application requires a reference to System.Data.SqlServerCe.dll









A application is composed in Six class


















  • SampleServiceAgent Class . This class derived from SyncAgent and contain SyncTable.













  • SampleServerSyncProvider. This class is derived from DbServerSyncProvider and contains the SyncAdapter.




  • SampleClientSyncProvider. This class is derived from SqlCeClientSyncProvider. In this example, this class contains only a connection string to the client database.




  • SampleStats. This class uses the statistics that are returned by the SyncAgent.




  • Program. This class sets up synchronization and calls methods from the Utility class.




  • Utility. This class handles all functionality that is not directly related to synchronization, such as holding connection string information and making changes to the server database. A complete Utility class is used in other topics









Key Parts of the API










Creating a SyncTable





The following code example creates a SyncTable object for the Customer table, specifies the synchronization direction, and specifies how the table should be created on the client. In this case, if the table already exists in the client database, the table will be dropped during the first synchronization.

























































C # Code





SyncTable customerSyncTable = new SyncTable("Customer");





customerSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;





customerSyncTable.SyncDirection = SyncDirection.DownloadOnly;





this.Configuration.SyncTables.Add(customerSyncTable);










Using the SqlSyncAdapterBuilder





The following code example creates a SyncAdapter for the Customer table. The synchronization adapter makes available to the server synchronization provider the specific commands that are required to interact with the server database. In this application, synchronization adapter is created by using the SqlSyncAdapterBuilder. The following information is specified for the SqlSyncAdapterBuilder and SyncAdapter:













  • The name of the table and the tombstone table. A tombstone table is used to track delete operations in the server database. For more information, see How to: Prepare a Server Database for Synchronization. If the tables are in a schema other than dbo, the schema must be specified.








  • The direction of synchronization. This controls which commands the SqlSyncAdapterBuilder creates. For more information about commands, see How to: Specify Snapshot, Download, Upload, and Bidirectional Synchronization.








  • The tracking columns in the server database. The columns are used to track when changes are made, so that only new changes are downloaded. You can include additional columns to track where changes are made. For more information, see How to: Prepare a Server Database for Synchronization.








  • The name of the SyncAdapter. This must match the name of the SyncTable. Therefore, it should not include the schema name.




For information about how to create commands manually instead of using the builder

























































C # Code





SqlSyncAdapterBuilder customerBuilder = new SqlSyncAdapterBuilder(serverConn);










customerBuilder.TableName = "Sales.Customer";





customerBuilder.TombstoneTableName = customerBuilder.TableName + "_Tombstone";





customerBuilder.SyncDirection = SyncDirection.DownloadOnly;





customerBuilder.CreationTrackingColumn = "InsertTimestamp";





customerBuilder.UpdateTrackingColumn = "UpdateTimestamp";





customerBuilder.DeletionTrackingColumn = "DeleteTimestamp";










SyncAdapter customerSyncAdapter = customerBuilder.ToSyncAdapter();





customerSyncAdapter.TableName = "Customer";





this.SyncAdapters.Add(customerSyncAdapter);










Specifying the New Anchor Command





The following code example specifies a command to retrieve a new anchor value from the server. The value is stored in the client database and is used by the commands that synchronize changes. During each synchronization, the new anchor value and the last anchor value from the previous synchronization are used: the set of changes between these upper and lower bounds is synchronized.





In this case, MIN_ACTIVE_ROWVERSION returns a timestamp value from a SQL Server database. (MIN_ACTIVE_ROWVERSION was introduced in SQL Server 2005 Service Pack 2.) A timestamp value is used because the tracking columns that are specified for the SqlSyncAdapterBuilder contain timestamp values. If the tracking columns contained date values, you could use a function such as GETUTCDATE() instead of MIN_ACTIVE_ROWVERSION. For more information about anchors, see How to: Prepare a Server Database for Synchronization.





The SyncSession class contains several string constants that can be used in synchronization commands. SyncNewReceivedAnchor is one of these constants. You could also use the literal @sync_new_received_anchor directly in your queries.















































C # Code





SqlCommand selectNewAnchorCommand = new SqlCommand();





string newAnchorVariable = "@" + SyncSession.SyncNewReceivedAnchor;





selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = min_active_rowversion() - 1";





selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.Timestamp);





selectNewAnchorCommand.Parameters[newAnchorVariable].Direction = ParameterDirection.Output;





selectNewAnchorCommand.Connection = serverConn;





this.SelectNewAnchorCommand = selectNewAnchorCommand;





Calling the Synchronize Method





The following code example instantiates SampleSyncAgent and calls the Synchronize method. In the SampleSyncAgent class, the SampleClientSyncProvider is specified as the LocalProvider and the SampleServerSyncProvider is specified as the RemoteProvider, and also the synchronization table that has already been described.















































C # Code





SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();





SyncStatistics syncStatistics = sampleSyncAgent.Synchronize();











































































































Complete code example in C#





using System;





using System.IO;





using System.Text;





using System.Data;





using System.Data.SqlClient;





using System.Data.SqlServerCe;





using Microsoft.Synchronization;





using Microsoft.Synchronization.Data;





using Microsoft.Synchronization.Data.Server;





using Microsoft.Synchronization.Data.SqlServerCe;










namespace Microsoft.Samples.Synchronization





{





class Program





{





static void Main(string[] args)





{





//The Utility class handles all functionality that is not





//directly related to synchronization, such as holding connection





//string information and making changes to the server database.





Utility util = new Utility();










//The SampleStats class handles information from the SyncStatistics





//object that the Synchronize method returns.





SampleStats sampleStats = new SampleStats();










//Delete and re-create the database. The client synchronization





//provider also enables you to create the client database





//if it does not exist.





util.SetClientPassword();





util.RecreateClientDatabase();










//Initial synchronization. Instantiate the SyncAgent





//and call Synchronize.





SampleSyncAgent sampleSyncAgent = new SampleSyncAgent();





SyncStatistics syncStatistics = sampleSyncAgent.Synchronize();





sampleStats.DisplayStats(syncStatistics, "initial");










//Make changes on the server.





util.MakeDataChangesOnServer();










//Subsequent synchronization.





syncStatistics = sampleSyncAgent.Synchronize();





sampleStats.DisplayStats(syncStatistics, "subsequent");










//Return server data back to its original state.





util.CleanUpServer();










//Exit.





Console.Write("\nPress Enter to close the window.");





Console.ReadLine();





}





}










//Create a class that is derived from





//Microsoft.Synchronization.SyncAgent.





public class SampleSyncAgent : SyncAgent





{





public SampleSyncAgent()





{





//Instantiate a client synchronization provider and specify it





//as the local provider for this synchronization agent.





this.LocalProvider = new SampleClientSyncProvider();










//Instantiate a server synchronization provider and specify it





//as the remote provider for this synchronization agent.





this.RemoteProvider = new SampleServerSyncProvider();










//Add the Customer table: specify a synchronization direction of





//DownloadOnly.





SyncTable customerSyncTable = new SyncTable("Customer");





customerSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;





customerSyncTable.SyncDirection = SyncDirection.DownloadOnly;





this.Configuration.SyncTables.Add(customerSyncTable);





}





}










//Create a class that is derived from





//Microsoft.Synchronization.Server.DbServerSyncProvider.





public class SampleServerSyncProvider : DbServerSyncProvider





{





public SampleServerSyncProvider()





{





//Create a connection to the sample server database.





Utility util = new Utility();





SqlConnection serverConn = new SqlConnection(util.ServerConnString);





this.Connection = serverConn;










//Create a command to retrieve a new anchor value from





//the server. In this case, we use a timestamp value





//that is retrieved and stored in the client database.





//During each synchronization, the new anchor value and





//the last anchor value from the previous synchronization





//are used: the set of changes between these upper and





//lower bounds is synchronized.





//





//SyncSession.SyncNewReceivedAnchor is a string constant;





//you could also use @sync_new_received_anchor directly in





//your queries.





SqlCommand selectNewAnchorCommand = new SqlCommand();





string newAnchorVariable = "@" + SyncSession.SyncNewReceivedAnchor;





selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = min_active_rowversion() - 1";





selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.Timestamp);





selectNewAnchorCommand.Parameters[newAnchorVariable].Direction = ParameterDirection.Output;





selectNewAnchorCommand.Connection = serverConn;





this.SelectNewAnchorCommand = selectNewAnchorCommand;















//Create a SyncAdapter for the Customer table by using





//the SqlSyncAdapterBuilder:





// * Specify the base table and tombstone table names.





// * Specify the columns that are used to track when





// changes are made.





// * Specify download-only synchronization.





// * Call ToSyncAdapter to create the SyncAdapter.





// * Specify a name for the SyncAdapter that matches the





// the name specified for the corresponding SyncTable.





// Do not include the schema names (Sales in this case).










SqlSyncAdapterBuilder customerBuilder = new SqlSyncAdapterBuilder(serverConn);










customerBuilder.TableName = "Sales.Customer";





customerBuilder.TombstoneTableName = customerBuilder.TableName + "_Tombstone";





customerBuilder.SyncDirection = SyncDirection.DownloadOnly;





customerBuilder.CreationTrackingColumn = "InsertTimestamp";





customerBuilder.UpdateTrackingColumn = "UpdateTimestamp";





customerBuilder.DeletionTrackingColumn = "DeleteTimestamp";










SyncAdapter customerSyncAdapter = customerBuilder.ToSyncAdapter();





customerSyncAdapter.TableName = "Customer";





this.SyncAdapters.Add(customerSyncAdapter);










}





}










//Create a class that is derived from





//Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider.





//You can just instantiate the provider directly and associate it





//with the SyncAgent, but you could use this class to handle client





//provider events and other client-side processing.





public class SampleClientSyncProvider : SqlCeClientSyncProvider





{










public SampleClientSyncProvider()





{





//Specify a connection string for the sample client database.





Utility util = new Utility();





this.ConnectionString = util.ClientConnString;





}





}










//Handle the statistics that are returned by the SyncAgent.





public class SampleStats





{





public void DisplayStats(SyncStatistics syncStatistics, string syncType)





{





Console.WriteLine(String.Empty);





if (syncType == "initial")





{





Console.WriteLine("****** Initial Synchronization ******");





}





else if (syncType == "subsequent")





{





Console.WriteLine("***** Subsequent Synchronization ****");





}










Console.WriteLine("Start Time: " + syncStatistics.SyncStartTime);





Console.WriteLine("Total Changes Downloaded: " + syncStatistics.TotalChangesDownloaded);





Console.WriteLine("Complete Time: " + syncStatistics.SyncCompleteTime);





Console.WriteLine(String.Empty);










}





}










public class Utility





{










private static string _clientPassword;










//Get and set the client database password.





public static string Password





{





get { return _clientPassword; }





set { _clientPassword = value; }





}










//Have the user enter a password for the client database file.





public void SetClientPassword()





{





Console.WriteLine("Type a strong password for the client");





Console.WriteLine("database, and then press Enter.");





Utility.Password = Console.ReadLine();





}










//Return the client connection string with the password.





public string ClientConnString





{





get { return @"Data Source='SyncSampleClient.sdf'; Password=" + Utility.Password; }





}










//Return the server connection string.





public string ServerConnString





{










get { return @"Data Source=localhost; Initial Catalog=SyncSamplesDb; Integrated Security=True"; }










}










//Make server changes that are synchronized on the second





//synchronization.





public void MakeDataChangesOnServer()





{





int rowCount = 0;










using (SqlConnection serverConn = new SqlConnection(this.ServerConnString))





{





SqlCommand sqlCommand = serverConn.CreateCommand();





sqlCommand.CommandText =





"INSERT INTO Sales.Customer (CustomerName, SalesPerson, CustomerType) " +





"VALUES ('Cycle Mart', 'James Bailey', 'Retail') " +










"UPDATE Sales.Customer " +





"SET SalesPerson = 'James Bailey' " +





"WHERE CustomerName = 'Tandem Bicycle Store' " +










"DELETE FROM Sales.Customer WHERE CustomerName = 'Sharp Bikes'";










serverConn.Open();





rowCount = sqlCommand.ExecuteNonQuery();





serverConn.Close();





}










Console.WriteLine("Rows inserted, updated, or deleted at the server: " + rowCount);





}










//Revert changes that were made during synchronization.





public void CleanUpServer()





{





using(SqlConnection serverConn = new SqlConnection(this.ServerConnString))





{





SqlCommand sqlCommand = serverConn.CreateCommand();





sqlCommand.CommandType = CommandType.StoredProcedure;





sqlCommand.CommandText = "usp_InsertSampleData";










serverConn.Open();





sqlCommand.ExecuteNonQuery();





serverConn.Close();





}





}










//Delete the client database.





public void RecreateClientDatabase()





{





using (SqlCeConnection clientConn = new SqlCeConnection(this.ClientConnString))





{





if (File.Exists(clientConn.Database))





{





File.Delete(clientConn.Database);





}





}










SqlCeEngine sqlCeEngine = new SqlCeEngine(this.ClientConnString);





sqlCeEngine.CreateDatabase();





}





}





}

Thursday, January 8, 2009

ArgumentException on Synchronize - Walkthrough Creating an Occasionally Connected Smart Device Application

Hi

1. I have resolved my issue I have remove all extra class and enumeration from reference’s file. Also import Microsoft.Synchronization.Data namespace in reference.cs class

2. If you access web service which is on your localhost than replace localhost with your machine ip address because device can not recognized localhost.
http://Machine ip address : port no/SyncServerPvoider/Service.asmx

3. Now connect your device emulator from Device manager and than after cradle that device, to cradle device emulator you want Microsoft Active sync software installed on your machine. For more information how to cradle your device visit http://newdotnetfx.blogspot.com/2009/01/connect-mobile-emulator-with-internet.html

Also I have copy past my web service reference.cs file for more clarification


//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//

//------------------------------------------------------------------------------
//
// This source code was auto-generated by Microsoft.CompactFramework.Design.Data, Version 2.0.50727.3053.
//
namespace xyz.SyncProxy {
using System.Diagnostics;
using System.Web.Services;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System;
using System.Xml.Serialization;
using System.Data;
using Microsoft.Synchronization.Data;
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap", Namespace="http://tempuri.org/")]
public partial class Service : System.Web.Services.Protocols.SoapHttpClientProtocol {
///
public Service() {
this.Url = "http://Machine IP Address: Port no /SyncServerPvoider/Service.asmx";
}
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetServerInfo", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public SyncServerInfo GetServerInfo(SyncSession session) {
object[] results = this.Invoke("GetServerInfo", new object[] {
session});
return ((SyncServerInfo)(results[0]));
}
///
public System.IAsyncResult BeginGetServerInfo(SyncSession session, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetServerInfo", new object[] {
session}, callback, asyncState);
}
///
public SyncServerInfo EndGetServerInfo(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((SyncServerInfo)(results[0]));
}
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetSchema", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public SyncSchema GetSchema(string[] tableNames, SyncSession session) {
object[] results = this.Invoke("GetSchema", new object[] {
tableNames,
session});
return ((SyncSchema)(results[0]));
}
///
public System.IAsyncResult BeginGetSchema(string[] tableNames, SyncSession session, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetSchema", new object[] {
tableNames,
session}, callback, asyncState);
}
///
public SyncSchema EndGetSchema(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((SyncSchema)(results[0]));
}
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetChanges", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession) {
object[] results = this.Invoke("GetChanges", new object[] {
groupMetadata,
syncSession});
return ((SyncContext)(results[0]));
}
///
public System.IAsyncResult BeginGetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetChanges", new object[] {
groupMetadata,
syncSession}, callback, asyncState);
}
///
public SyncContext EndGetChanges(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((SyncContext)(results[0]));
}
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ApplyChanges", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession) {
object[] results = this.Invoke("ApplyChanges", new object[] {
groupMetadata,
dataSet,
syncSession});
return ((SyncContext)(results[0]));
}
///
public System.IAsyncResult BeginApplyChanges(SyncGroupMetadata groupMetadata, System.Data.DataSet dataSet, SyncSession syncSession, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("ApplyChanges", new object[] {
groupMetadata,
dataSet,
syncSession}, callback, asyncState);
}
///
public SyncContext EndApplyChanges(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((SyncContext)(results[0]));
}
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string HelloWorld() {
object[] results = this.Invoke("HelloWorld", new object[0]);
return ((string)(results[0]));
}
///
public System.IAsyncResult BeginHelloWorld(System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("HelloWorld", new object[0], callback, asyncState);
}
///
public string EndHelloWorld(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
}
/*///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncSession {
private int originatorIdField;
private System.Guid clientIdField;
private SyncParameter[] customParametersField;
///
public int OriginatorId {
get {
return this.originatorIdField;
}
set {
this.originatorIdField = value;
}
}
///
public System.Guid ClientId {
get {
return this.clientIdField;
}
set {
this.clientIdField = value;
}
}
///
[System.Xml.Serialization.XmlElementAttribute("CustomParameters")]
public SyncParameter[] CustomParameters {
get {
return this.customParametersField;
}
set {
this.customParametersField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncParameter {
private string nameField;
private object valueField;
///
public string Name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
///
public object Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncConflict {
private ConflictType conflictTypeField;
private string errorMessageField;
private SyncStage syncStageField;
private System.Data.DataTable serverChangeField;
private System.Data.DataTable clientChangeField;
///
public ConflictType ConflictType {
get {
return this.conflictTypeField;
}
set {
this.conflictTypeField = value;
}
}
///
public string ErrorMessage {
get {
return this.errorMessageField;
}
set {
this.errorMessageField = value;
}
}
///
public SyncStage SyncStage {
get {
return this.syncStageField;
}
set {
this.syncStageField = value;
}
}
///
public System.Data.DataTable ServerChange {
get {
return this.serverChangeField;
}
set {
this.serverChangeField = value;
}
}
///
public System.Data.DataTable ClientChange {
get {
return this.clientChangeField;
}
set {
this.clientChangeField = value;
}
}
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public enum ConflictType {
///
Unknown,
///
ErrorsOccurred,
///
ClientUpdateServerUpdate,
///
ClientUpdateServerDelete,
///
ClientDeleteServerUpdate,
///
ClientInsertServerInsert,
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public enum SyncStage {
///
ReadingSchema,
///
CreatingSchema,
///
ReadingMetadata,
///
CreatingMetadata,
///
DeletingMetadata,
///
WritingMetadata,
///
UploadingChanges,
///
DownloadingChanges,
///
ApplyingInserts,
///
ApplyingUpdates,
///
ApplyingDeletes,
///
GettingInserts,
///
GettingUpdates,
///
GettingDeletes,
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncTableProgress {
private string tableNameField;
private int insertsField;
private int updatesField;
private int deletesField;
private int changesAppliedField;
private int changesFailedField;
private SyncConflict[] conflictsField;
///
public string TableName {
get {
return this.tableNameField;
}
set {
this.tableNameField = value;
}
}
///
public int Inserts {
get {
return this.insertsField;
}
set {
this.insertsField = value;
}
}
///
public int Updates {
get {
return this.updatesField;
}
set {
this.updatesField = value;
}
}
///
public int Deletes {
get {
return this.deletesField;
}
set {
this.deletesField = value;
}
}
///
public int ChangesApplied {
get {
return this.changesAppliedField;
}
set {
this.changesAppliedField = value;
}
}
///
public int ChangesFailed {
get {
return this.changesFailedField;
}
set {
this.changesFailedField = value;
}
}
///
public SyncConflict[] Conflicts {
get {
return this.conflictsField;
}
set {
this.conflictsField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncGroupProgress {
private string groupNameField;
private SyncTableProgress[] tablesProgressField;
///
public string GroupName {
get {
return this.groupNameField;
}
set {
this.groupNameField = value;
}
}
///
public SyncTableProgress[] TablesProgress {
get {
return this.tablesProgressField;
}
set {
this.tablesProgressField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncContext {
private SyncGroupProgress groupProgressField;
private int originatorIdField;
private SyncAnchor newAnchorField;
private SyncAnchor maxAnchorField;
private int batchCountField;
private System.Data.DataSet dataSetField;
///
public SyncGroupProgress GroupProgress {
get {
return this.groupProgressField;
}
set {
this.groupProgressField = value;
}
}
///
public int OriginatorId {
get {
return this.originatorIdField;
}
set {
this.originatorIdField = value;
}
}
///
public SyncAnchor NewAnchor {
get {
return this.newAnchorField;
}
set {
this.newAnchorField = value;
}
}
///
public SyncAnchor MaxAnchor {
get {
return this.maxAnchorField;
}
set {
this.maxAnchorField = value;
}
}
///
public int BatchCount {
get {
return this.batchCountField;
}
set {
this.batchCountField = value;
}
}
///
public System.Data.DataSet DataSet {
get {
return this.dataSetField;
}
set {
this.dataSetField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncAnchor {
private byte[] anchorField;
///
[System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")]
public byte[] Anchor {
get {
return this.anchorField;
}
set {
this.anchorField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncTableMetadata {
private string tableNameField;
private SyncDirection syncDirectionField;
private SyncAnchor lastSentAnchorField;
private SyncAnchor lastReceivedAnchorField;
///
public string TableName {
get {
return this.tableNameField;
}
set {
this.tableNameField = value;
}
}
///
public SyncDirection SyncDirection {
get {
return this.syncDirectionField;
}
set {
this.syncDirectionField = value;
}
}
///
public SyncAnchor LastSentAnchor {
get {
return this.lastSentAnchorField;
}
set {
this.lastSentAnchorField = value;
}
}
///
public SyncAnchor LastReceivedAnchor {
get {
return this.lastReceivedAnchorField;
}
set {
this.lastReceivedAnchorField = value;
}
}
}
///
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public enum SyncDirection {
///
DownloadOnly,
///
UploadOnly,
///
Bidirectional,
///
Snapshot,
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncGroupMetadata {
private string groupNameField;
private SyncAnchor newAnchorField;
private SyncAnchor maxAnchorField;
private int batchCountField;
private SyncTableMetadata[] tablesMetadataField;
///
public string GroupName {
get {
return this.groupNameField;
}
set {
this.groupNameField = value;
}
}
///
public SyncAnchor NewAnchor {
get {
return this.newAnchorField;
}
set {
this.newAnchorField = value;
}
}
///
public SyncAnchor MaxAnchor {
get {
return this.maxAnchorField;
}
set {
this.maxAnchorField = value;
}
}
///
public int BatchCount {
get {
return this.batchCountField;
}
set {
this.batchCountField = value;
}
}
///
public SyncTableMetadata[] TablesMetadata {
get {
return this.tablesMetadataField;
}
set {
this.tablesMetadataField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncSchema {
private System.Data.DataSet schemaDataSetField;
///
public System.Data.DataSet SchemaDataSet {
get {
return this.schemaDataSetField;
}
set {
this.schemaDataSetField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncTableInfo {
private string tableNameField;
private string descriptionField;
///
public string TableName {
get {
return this.tableNameField;
}
set {
this.tableNameField = value;
}
}
///
public string Description {
get {
return this.descriptionField;
}
set {
this.descriptionField = value;
}
}
}
///
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class SyncServerInfo {
private SyncTableInfo[] tablesInfoField;
///
public SyncTableInfo[] TablesInfo {
get {
return this.tablesInfoField;
}
set {
this.tablesInfoField = value;
}
}
}*/
}
Thanks
Abhishek Hingu
http://www.indianic.com/

Wednesday, January 7, 2009

Connect Mobile Emulator with Internet

Hi Friends

I am learning window mobile application development. I made one application in which i want to browse some web site.on window mobile device my application work fine but on Emulator it does not work, because whenever emulator launch it is not adopt my computer network setting ( which you can say Microsoft Development team fault ;). so I dig in to mobile emulator setting and find solution by which we can set our computer networking setting to emulator. for that Steps are
  1. First Install Microsoft ActiveSync software according to your Operating System
  2. Run Microsoft ActiveSync Software and browse File >> Connection Settings.
  3. In Connection Setting dialog box select DMA from dorp down display below Allow connection to one of the following
  4. Open Device Emulator Manager from Visual studio
  5. Right click on emulator and select connect option
  6. Once emulator running again right click on emulator and cardle the device

If you see nothing happened to your Windows Mobile Device Center, it doesn’t mean you missed some steps from the above. It happened only because the Device Emulator 1.0 is the one comes with Visual Studio 2005 has this cradle problem on Windows Vista.

The solution is to download Microsoft Device Emulator 2.0 and by installing 2.0, it will replace the old one. Read this note from its download page: “DeviceEmulator 2.0 has taken a few design changes to work with the Windows Vista operating system that enables the emulator to be cradled using the Windows Mobile Device Center”.

Thanks

Abhishek Hingu

Friday, January 2, 2009

Getting run time error message "The database file has been created earlier version of Sql Server compact."

Problem

When running samples/demos of the Sync Services intended for SQL Server CE 3.5 Beta 2 you receive the following message:
"The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method"
Cause

The reference in your project to the System.Data.SqlServerCe assembly is pointing to an older version of the file. This may occur if you already have Visual Studio 2005 installed on your PC.

Solution
In the Visual Studio project, ensure the file path of the System.Data.SqlServerCe reference points to the correct version – in this case SQL Server CE 3.5 Beta 2 (Desktop):
C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Desktop\System.Data.SqlServerCe.dll

An example of an incorrect file reference for SQL Server CE 3.5 Beta 2 is as follows:
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlServerCe.dll

Wednesday, December 31, 2008

Ajax application Security

Ajax is not issue about application security but application programming model dose make application vulnerability more porous as per software engineering.JavaScript-powered client-server interactions do enlarge the attack surface.

Ajax application security issue can be address by take care in desiging of application architechture.Here I will going to introduce that thing which can resolve the Ajax application security problem.

SQL Injection : In these attacks, hackers first research common SQL error messages to find vulnerable pages and then modify Select statements to, for example, use a simple TextBox to gain access to a database. Ajax complicates matters because it makes it possible to write SQL expressions on the client side.

Tips to prevent this kind of attacke are:
  1. Use CustomErrors pages in the WebConfig file to prevent attackers from identifying an application's particular vulnerability.
  2. Use Stored procedures or parameterized SQL queries instead of dynamically created SQL queries.
  3. Perform input validation on the server side, not through JavaScript.
  4. Use the Least Privileges account for your database and do not allow access to system data. This builds on the notion that security should be implemented in single layers, Software Engineering stated: "You don't want them to be able to thwart one and then get to the data."

Information Leakage : If the JavaScript APIs that power an Ajax application are not properly secured, hackers can use application workflow data exposed on the client side to piece together server-side services. The best way to protect against this, not surprisingly, is to keep security validation on the server side. The only validation that should occur on the client side is that which defines the user experience

Cross site Scripting : In these attacks, hackers foist malicious JavaScript onto unsuspecting users. This tends to happen on Web sites featuring a simple TextBox and a button click that encapsulates text. Instead of, say, posting a comment in a forum, hackers will use this TextBox to put in a script tag to transfer large sums of money from your bank account to theirs. Ajax, as you might expect, leaves more APIs open than does a traditional Web application.

To Protect against Cross-site-scripting I would urge you to do your own validation to make sure you're not allowing this type of input." To best accomplish this, he recommended the use of a white list, which specifically states only the characters that a user is allowed to type in the TextBox. Make sure this list does not include script tags or HTML code.

Cross-Site Request Forging: These attacks use malicious image tags in emails and leverage browser cookies. The image acts as a placeholder for what is really a query string to make that aforementioned money transfer. Once that page loads, the image request triggers an HTTP GET action, and cookies are passed along with it. "The variables coming in from the query string look exactly the same as a post. It's using that cookie that's stored on your computer, and your information, to make that query work,"
Protecting against
cross-site request forging involves three best practices, he continued. The first is to use HTTP POST data as opposed to HTTP GET data; the latter can be used for retrieving data, but it should not be used for performing any sort of action using that data. The second is to use one-time, per-token requests. The third is to stand up to nagging end users and stop using persistent cookies for authentication -- especially if sensitive data sits behind a log-in screen.
JavaScript Hijacking: This variation of cross-site request forging, which thanks to ASP.NET and IIS authentication does not occur in Internet Explorer, sets script tags to a particular URL that, when HTTP GET is passed, will return a
JSON-formatted string. From there, the hacker modifies the object prototype to peer into JSON values when they are created. In addition to using the HTTP POST protocol, Lombardo said the best way to protect against JavaScript hijacking is to encode JSON strings on the server side, not the client side.
Lombardo offered two tidbits of advice that were not covered in his discussions of the five common Ajax security vulnerabilities.
First, he recommended removing the
WSDL from Web services, as this only gives hackers information about an application that they otherwise would not be able to determine.

Second, he said it is a good idea to place WebMethods and WebServices in separate classes.

Thanks & Regards

Abhishek Hingu

Sr. Software Eng.

Indianic Infotech Pvt Ltd