本文介绍了WCF上的同步服务值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好,我已经创建了一个Windows桌面应用程序,用户可以使用它来创建使用Sync Services(基于WCF)的SDF。我按照http://blogs.msdn.com/sync/archive/2008/07/14/using-wcf-for-communcation-in-a-mobile-sync-application.aspx 上的示例进行了访问。 />设计同步服务。然后我将服务引用添加到我的桌面项目以生成代理。以下是代理中的GetSchema方法:zh。公共SyncSchema GetSchema(string [] tableNames,SyncSession syncSession) {return base.Channel.GetSchema(tableNames,syncSession) ;但是我仍然得到以下错误: "类型的对象System.String []'无法转换为类型'System.Collections.ObjectModel。 Collection`1 [System.String]'。" " System.SruntimeType.CheckValue(Object value,Binder binder,CultureInfo culture,BindingFlags invokeAttr)\\\ System.Reflection.MethodBase.CheckArguments(Object []参数,Binder binder,BindingFlags invokeAttr,CultureInfo culture,Signature sig) )System.Reflection.RuntimeMethodInfo.Invoke中的System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo culture,Boolean skipVisibilityChecks)\\\\ n (对象obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)\\\ at System.Reflection.MethodBase.Invoke(Object obj,Object [] parameters)\\\\\ at Microsoft。 Microsoft.Synchronization.SyncAgent.Synchronize()\在Microsoft.Synchronization.SyncAgent.InitClientSchema()\\\\ n中的Synchronization.Data.ServerSyncProviderProxy.GetSchema(Collection`1 tableNames,SyncSession syncSession)\\\\ n r\\ n在Timmons.VectorControl.Mobile.SDFCreator.SDFCreatorForm.SynchronizeTables()中的C:\\Projects \\Newport_News_Mobile \\src \\Timmons.VectorControl.Mobile \\Timmons.VectorControl。 Mobile.SDFCreator \\SDFCreatorForm.cs:第255行" 我花了好几个小时追逐这个没有运气。我开始想知道在WCF上获取同步服务是否真的值得。 这是我的Iservice代码 公共接口ISyncService { [ OperationContract] 字符串GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); #region sync service服务器提供程序抽象方法 [OperationContract] SyncServerInfo GetServerInfo(SyncSession syncSession); [OperationContract] SyncContext ApplyChanges(Microsoft.Synchronization.Data.SyncGroupMetadata groupMetadata,DataSet dataSet,SyncSession syncSession); [OperationContract] SyncContext GetChanges(SyncGroupMetadata groupMetadata,SyncSession syncSession); [OperationContract] SyncSchema GetSchema(string [] tableNam es,SyncSession syncSession); #endregion 我也尝试从移动应用程序创建SDF,但不断获得相同的参数异常。以下是Service.cs的代码 private void CreateServerProvider() { SqlConnection serverConnection; SqlSyncAdapterBuilder构建器; // serverConnection = new SqlConnection(_connString); serverConnection = new SqlConnection(string.Format(" server = {0}; database = {1 }; integrated security = true",_ server,_db)); serverConnection.Open(); _serverSyncProvider = new DbServerSyncProvider(); _serverSyncProvider.Connection = serverConnection; #region仅下载同步 SyncAdapter adaptorWorkOrder =新的SyncAdapter(_tableOwner + TableWorkOrder); #region Inserts SqlCommand incInsWorkOrderCmd = new SqlCommand(); incInsWorkOrderCmd.CommandType = CommandType.StoredProcedure; incInsWorkOrderCmd.CommandText = _tableOwner + SPWorkOrderIncrementalInsert; incInsWorkOrderCmd.Parameters.Add(" @" + SyncSession.SyncLastReceivedAnchor,SqlDbType.Binary,8); incInsWorkOrderCmd.Parameters.Add(" @" + SyncSession.SyncNewReceivedAnchor,SqlDbType.Binary,8); adaptorWorkOrder.SelectIncrementalInsertsCommand = incInsWorkOrderCmd; #endr egion #region Updates SqlCommand incUpdWorkOrderCmd = new SqlCommand(); incUpdWorkOrderCmd.CommandType = CommandType.StoredProcedure; incUpdWorkOrderCmd.CommandText = _tableOwner + SPWorkOrderIncrementalUpdate; incUpdWorkOrderCmd.Parameters.Add(" @" + SyncSession.SyncLastReceivedAnchor,SqlDbType.Binary,8); incUpdWorkOrderCmd.Parameters.Add(" @" + SyncSession.SyncNewReceivedAnchor,SqlDbType.Binary,8); adaptorWorkOrder.SelectIncrementalUpdatesCommand = incUpdWorkOrderCmd; #endregion #region删除 SqlCommand incDelTimeCodesCmd = new SqlCommand(); incDelTimeCodesCmd.CommandType = CommandType.StoredProcedure; incDelTimeCodesCmd。 CommandText = _tableOwner + SPWorkOrderIncrementalDelete; incDelTimeCodesCmd.Parameters.Add(" @" + SyncSession.SyncLastReceivedAnchor,SqlDbType.Binary,8); incDelTimeCodesCmd.Parameters.Add(" @" + SyncSession .SyncNewReceivedAnchor,SqlDbType.Binary,8); adaptorWorkOrder.SelectIncrementa lDeletesCommand = incDelTimeCodesCmd; #endregion _serverSyncProvider.SyncAdapters.Add(adaptorWorkOrder); #endregion SqlCommand anchorCmd = new SqlCommand (); anchorCmd.CommandType = CommandType.Text; anchorCmd.CommandText =" Select @" + SyncSession.SyncNewReceivedAnchor +" = min_active_rowversion() - 1" ;; //anchorCmd.CommandText =" Select @" + SyncSession.SyncNewReceivedAnchor +" = @@ DBTS" ;; //对于SQL Server 2005 SP2,使用" min_active_rowversion() - 1" anchorCmd.Parameters.Add(" @" + SyncSession.SyncNewReceivedAnchor,SqlDbType.Timestamp).Direction = ParameterDirection。输出; _serverSyncProvider.SelectNewAnchorCommand = anchorCmd; 非常感谢任何帮助。 感谢解决方案 看一下这个帖子 http://social.microsoft.com/Forums/en-US/uklaunch2007ado.net/thread/95b24ae5-712f-4bb7-8287-5f20ff009756 并查看是否能解决您的问题。,Gayathri TK Hello, I have created a windows desktop application that user would use to create SDF using Sync Services (WCF based). I followed the sample on http://blogs.msdn.com/sync/archive/2008/07/14/using-wcf-for-communcation-in-a-mobile-sync-application.aspx to design the sync service. I then added service reference to my desktop project to generate proxies. Here is what GetSchema method in the proxy looks: public SyncSchema GetSchema(string[] tableNames, SyncSession syncSession) { return base.Channel.GetSchema(tableNames, syncSession); } However I am still getting following error: "Object of type 'System.String[]' cannot be converted to type 'System.Collections.ObjectModel.Collection`1[System.String]'." " at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)\r\n at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)\r\n at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)\r\n at Microsoft.Synchronization.Data.ServerSyncProviderProxy.GetSchema(Collection`1 tableNames, SyncSession syncSession)\r\n at Microsoft.Synchronization.SyncAgent.InitClientSchema()\r\n at Microsoft.Synchronization.SyncAgent.Synchronize()\r\n at Timmons.VectorControl.Mobile.SDFCreator.SDFCreatorForm.SynchronizeTables() in C:\\Projects\\Newport_News_Mobile\\src\\Timmons.VectorControl.Mobile\\Timmons.VectorControl.Mobile.SDFCreator\\SDFCreatorForm.cs:line 255" I have spend hours chasing this down with no luck. I am begining to wonder if getting sync service on WCF is really worth it. Here is my Iservice code public interface ISyncService { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); #region sync service Server provider abstract methods [OperationContract] SyncServerInfo GetServerInfo(SyncSession syncSession); [OperationContract] SyncContext ApplyChanges(Microsoft.Synchronization.Data.SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession); [OperationContract] SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession); [OperationContract] SyncSchema GetSchema(string[] tableNames, SyncSession syncSession); #endregion } I also tried to create SDF from Mobile app but keep getting same argument exception. Here is the code for the Service.cs private void CreateServerProvider() { SqlConnection serverConnection; SqlSyncAdapterBuilder builder; //serverConnection = new SqlConnection(_connString); serverConnection = new SqlConnection(string.Format("server = {0}; database = {1}; integrated security = true", _server, _db)); serverConnection.Open(); _serverSyncProvider = new DbServerSyncProvider(); _serverSyncProvider.Connection = serverConnection; #region Download Only Sync SyncAdapter adaptorWorkOrder = new SyncAdapter(_tableOwner + TableWorkOrder); #region Inserts SqlCommand incInsWorkOrderCmd = new SqlCommand(); incInsWorkOrderCmd.CommandType = CommandType.StoredProcedure; incInsWorkOrderCmd.CommandText = _tableOwner + SPWorkOrderIncrementalInsert; incInsWorkOrderCmd.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8); incInsWorkOrderCmd.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Binary, 8); adaptorWorkOrder.SelectIncrementalInsertsCommand = incInsWorkOrderCmd; #endregion #region Updates SqlCommand incUpdWorkOrderCmd = new SqlCommand(); incUpdWorkOrderCmd.CommandType = CommandType.StoredProcedure; incUpdWorkOrderCmd.CommandText = _tableOwner + SPWorkOrderIncrementalUpdate; incUpdWorkOrderCmd.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8); incUpdWorkOrderCmd.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Binary, 8); adaptorWorkOrder.SelectIncrementalUpdatesCommand = incUpdWorkOrderCmd; #endregion #region Deletes SqlCommand incDelTimeCodesCmd = new SqlCommand(); incDelTimeCodesCmd.CommandType = CommandType.StoredProcedure; incDelTimeCodesCmd.CommandText = _tableOwner + SPWorkOrderIncrementalDelete; incDelTimeCodesCmd.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Binary, 8); incDelTimeCodesCmd.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Binary, 8); adaptorWorkOrder.SelectIncrementalDeletesCommand = incDelTimeCodesCmd; #endregion _serverSyncProvider.SyncAdapters.Add(adaptorWorkOrder); #endregion SqlCommand anchorCmd = new SqlCommand(); anchorCmd.CommandType = CommandType.Text; anchorCmd.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = min_active_rowversion() - 1"; //anchorCmd.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = @@DBTS"; // for SQL Server 2005 SP2, use "min_active_rowversion() - 1" anchorCmd.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Timestamp).Direction = ParameterDirection.Output; _serverSyncProvider.SelectNewAnchorCommand = anchorCmd; Any help is highly appreciated. Thanks 解决方案 Hi, Take a look at this thread http://social.microsoft.com/Forums/en-US/uklaunch2007ado.net/thread/95b24ae5-712f-4bb7-8287-5f20ff009756 and see if that solves your problem.Thanks,Gayathri TK 这篇关于WCF上的同步服务值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 10:37