locked
Null ServerProvider object when calling SyncAgent.Synchronize() via web service RRS feed

  • Question

  • I am getting a null ServerProvider object in my web service when calling SyncAgent.Synchronize(). My code was working fine before I split out client and server to use the web service. I have the four WebMethods required in the web service (omitted for brevity).

     

    I am building all SyncAdapter tables and commands from Oracle schema on the web server. I'm getting the client SyncTable list through a separate SyncWebServiceSupportProxy web service.

     

    Client code:

    Code Block

        Private Sub btnSync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSync.Click

            Dim syncAgent As New SyncAgent()
            Dim connString As String = "Data Source=" & SynchronizationHelper.Common.ParseEnvironmentVariable(LOCAL_DB_PATH) & LOCAL_DB_CONNECTION_STRING_ARGS
            serverSyncHelper.CreateSqlCeDatabase(LOCAL_DB_PATH, LOCAL_DB_CONNECTION_STRING_ARGS, False)

            Dim clientSyncProvider As SqlCeClientSyncProvider = New SqlCeClientSyncProvider(connString)
            syncAgent.LocalProvider = clientSyncProvider

            Dim syncWebService As SyncWebServiceProxy.SyncService = New SyncWebServiceProxy.SyncService()
            syncAgent.RemoteProvider = New Microsoft.Synchronization.Data.Server.ServerSyncProviderProxy(syncWebService)

            Dim syncWebServiceSupport As New SyncWebServiceSupportProxy.SyncServiceSupport()
            For Each tableName As String In syncWebServiceSupport.GetSyncableTables()
                Dim syncTable As New SyncTable(tableName)
                syncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable
                syncTable.SyncTableTransferOption = SyncTableTransferOption.DownloadOnly

                clientSyncProvider.Configuration.SyncTables.Add(tableName)

            Next

            ' Exception below is:
            ' "Exception has been thrown by the target of an invocation.

            ' InnerException is:
            ' {"System.Web.Services.Protocols.SoapException: Server was unable to process request. --->
            ' System.NullReferenceException: Object reference not set to an instance of an object.
            ' at SyncService..ctor() in C:\code\Trunk\OmsAppServer\OmsAppServer\App_Code\SyncService.vb:line 44
            Dim syncStats As SyncStatistics = syncAgent.Synchronize()

     

        End Sub

     

     

    Constructor in web service:

     

    Code Block

        Public Sub New()
            Dim serverSyncHelper As New SynchronizationHelper.Server()
            Dim tables As List(Of String) = serverSyncHelper.GetSyncableTables()
            For Each tableName As String In tables
                Dim syncAdapter As SyncAdapter = New SyncAdapter(tableName)

                '// select incremental inserts command
                Dim incInsOrdersCmd As OracleCommand = New OracleCommand()
                incInsOrdersCmd.CommandType = CommandType.Text
                incInsOrdersCmd.CommandText = serverSyncHelper.GetSelectIncrementalInsertsCommand(tableName)
                incInsOrdersCmd.Parameters.Add(":" + SyncSession.SyncLastReceivedAnchor, OracleType.Timestamp)
                incInsOrdersCmd.Parameters.Add(":" + SyncSession.SyncNewReceivedAnchor, OracleType.Timestamp)

                syncAdapter.SelectIncrementalInsertsCommand = incInsOrdersCmd


                '// select incremental updates command
                Dim incUpdOrdersCmd As OracleCommand = New OracleCommand()
                incUpdOrdersCmd.CommandType = CommandType.Text
                incUpdOrdersCmd.CommandText = serverSyncHelper.GetSelectIncrementalUpdatesCommand(tableName)
                incUpdOrdersCmd.Parameters.Add(":" + SyncSession.SyncLastReceivedAnchor, OracleType.Timestamp)
                incUpdOrdersCmd.Parameters.Add(":" + SyncSession.SyncNewReceivedAnchor, OracleType.Timestamp)

                syncAdapter.SelectIncrementalUpdatesCommand = incUpdOrdersCmd

     

      'HERE'S LINE 44:

                _serverProvider.SyncAdapters.Add(syncAdapter)

     

                Dim anchorCmd As OracleCommand = New OracleCommand()
                anchorCmd.CommandType = CommandType.Text
                anchorCmd.CommandText = _
                        "BEGIN " & _
                        "   SELECT MAX(idx) INTO :" + SyncSession.SyncNewReceivedAnchor + " FROM (SELECT MAX(" & serverSyncHelper.GetCreatedDateField(tableName) & ") AS idx FROM " & tableName & " UNION SELECT (" & serverSyncHelper.GetModifiedDateField(tableName) & ") AS idx FROM " & tableName & ");" & _
                        "END;"
                anchorCmd.Parameters.Add(":" + SyncSession.SyncNewReceivedAnchor, OracleType.Timestamp).Direction = ParameterDirection.Output
                _serverProvider.SelectNewAnchorCommand = anchorCmd
            Next
        End Sub

     

     


     

     

    • Moved by Hengzhe Li Friday, April 22, 2011 7:53 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Friday, November 16, 2007 5:48 AM

Answers

  • Too many late nights - I need to instantiate the _serverProvider and give it a legit connection string.

     

    Thanks.

     

    Friday, November 16, 2007 2:55 PM

All replies

  • Too many late nights - I need to instantiate the _serverProvider and give it a legit connection string.

     

    Thanks.

     

    Friday, November 16, 2007 2:55 PM
  • Might you share a working sample.  Others are having issues with Oracle and wcf.

     

    Thanks!

     

    Sean Kelley

    Program Manager

    Microsoft

     

    Tuesday, November 11, 2008 5:02 AM
    Moderator
  • We're not using SyncServices to sync (we've gone custom), and we're not using WCF (uh, yet). Sorry.

     

    Dave Michel

    Magenic

    Tuesday, November 11, 2008 5:17 AM
  • Dave,

     

    Why did you choose to go custom just out of curiosity?

     

    -Sean

     

    Tuesday, November 11, 2008 4:21 PM
    Moderator
  • We needed to have a concept of a SyncUnit, which is a multi-table grouping of related data in a single transaction. We can arbitrarily group data with our custom solution in a way that we couldn't with Synchronization Services. We also could optimized queries across tables appropriate to our application that greatly improved performance (we're syncing 70 tables).

     

    We're not able to use SQL Server 2008 Change Tracking (our client is an Oracle shop), so we've found our custom sync is more performance and reliable under load. I'd use SyncServices in a flash if we had a simpler set of requirements.

     

    Dave

    Tuesday, November 11, 2008 4:36 PM