locked
Exception on sync for mobile OCS app RRS feed

  • Question

  • Hi,

    I am working on a Windows Mobile App with .NET CF 3.5 and C#.

    I tried to build synchronizing into my application like in this walkthrough: http://msdn.microsoft.com/en-us/library/cc488004.aspx

    I tested this with a SQL Server 2005 Express and a Northwind database. It seemed to work fine. Then I uninstalled the SQL Server and installed SQL Server 2008 and tried to create a new sample with my own database but I can't get it to work.


    I get a TargetInvocationException with an inner SoapHeaderException. My VisualStudio is german, so i can't post the exact english error Message but it says something like that: "Error while deserializing parameter http://tempuri.org/:groupMetadata. Error in line 2, position 88. \"EndElement\" \"groupMetadata\" from Namespace \"http://tempuri.org/\" is not expected. Element \"_batchCount\" is expected to be the next element."

    I don't know how to fix that. Can anyone help me?
    Friday, February 12, 2010 1:05 PM

Answers

  • I finally got it! :) just stupid

    I tried to add another simple service method that returns a string. After adding it to the contract, updating the WebReference and deleting the Sync classes in Reference.cs not only the simple method works but the synchronize works, too. "WHAT?! why?"

    After some testing around I figured it out. The problem was that I added the WebReference and afterwards remembered that I must set the XmlSerializerFormat attribute. That doesn't work. You have to put the attribute first and then add the WebReference or Update the WebReference after adding the attribute.

    Thanks to everyone who responded
    • Marked as answer by Yunwen Bai Thursday, February 18, 2010 9:31 PM
    Wednesday, February 17, 2010 2:06 PM

All replies

  • Since SQL 2005 + Northwind combination is working for you, can you try "SQL Server 2008 + Northwind" and see if it is working for you? 

    You probably need a new client database on the Mobile Device of each try, and maybe need to create a new web service.

    When SQL Server 2008 + Northwind is working, then you can try the same approach with your own database. 

    Thanks.


    Leo Zhou ------ This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, February 12, 2010 8:04 PM
    Answerer
  • Hi,
    It seems the error is towards the Web Services.
    Are you using web service to connect the Service? then check that part and also check whether connection is updated as per the new database.


    Thanks.
    Biju
    Saturday, February 13, 2010 6:58 AM
  • hi kreo,

    try to review your WCF service contracts are updated and also to update the WCF service reference on your client side.
    Sunday, February 14, 2010 11:04 AM
  • I created a completely new project when I switched the database and rewrote everything from scratch (multiple times). The LocalDataCache generates the needed sync code. I've customized my App.config and deleted all redundant classes from Reference.cs.

    I already checked the typical mistakes like XMLSerializerFormat in the contract and replaced all localhost entries in App.config with my IP but it doesn't work. I can see the service in the browser from my desktop and my mobile device.

    Thats my App.config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
      </configSections>
      <connectionStrings>
        <add name="SyncLibrary.Properties.Settings.ServerEvocuraMobileDBConnectionString"
          connectionString="Data Source=192.168.0.2;Initial Catalog=MobileDB;Persist Security Info=True;User ID=[...];Password=[...]"
          providerName="System.Data.SqlClient" />
      </connectionStrings>
      <system.web>
        <compilation debug="true" />
      </system.web>
      <system.serviceModel>
        <services>
          <service name="SyncLibrary.LocalDataCacheSyncService" behaviorConfiguration="SyncLibrary.LocalDataCacheSyncServiceBehavior">
            <host>
              <baseAddresses>
                <add baseAddress="http://192.168.0.2:8731/LocalDataCacheSyncService/"   />
              </baseAddresses>
            </host>
            <endpoint address=""  binding="basicHttpBinding" contract="SyncLibrary.ILocalDataCacheSyncContract">
              <identity>
                <dns value="192.168.0.2"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SyncLibrary.LocalDataCacheSyncServiceBehavior">
              <serviceMetadata httpGetEnabled="True"/>
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>


    and here is my contract:

        [XmlSerializerFormat]
        [ServiceContract]
        public interface ILocalDataCacheSyncContract {
            
            [OperationContract]
            SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession);
            
            [OperationContract]
            SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);
            
            [OperationContract]
            SyncSchema GetSchema(string[] tableNames, SyncSession syncSession);
            
            [OperationContract]
            SyncServerInfo GetServerInfo(SyncSession syncSession);
        }


    EDIT: I just tried to disable the SQL Server change tracking. That makes no difference
    Tuesday, February 16, 2010 12:26 PM
  • interesting. you have a similar case here: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/e23f8947-0eb8-4663-8360-98c3a314f7b4

    have you tried looking tracing the WCF message or looking at the WSDL file and the proxy generated on the client side?
    Tuesday, February 16, 2010 11:18 PM
  • Besides JuneT suggested, is it failed with sync operations only ? can you put a new contract just send back/forward a few string values to see if it works on the device?

    thanks
    yunwen
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, February 17, 2010 8:06 AM
  • I finally got it! :) just stupid

    I tried to add another simple service method that returns a string. After adding it to the contract, updating the WebReference and deleting the Sync classes in Reference.cs not only the simple method works but the synchronize works, too. "WHAT?! why?"

    After some testing around I figured it out. The problem was that I added the WebReference and afterwards remembered that I must set the XmlSerializerFormat attribute. That doesn't work. You have to put the attribute first and then add the WebReference or Update the WebReference after adding the attribute.

    Thanks to everyone who responded
    • Marked as answer by Yunwen Bai Thursday, February 18, 2010 9:31 PM
    Wednesday, February 17, 2010 2:06 PM