locked
Anyone successful with mobile sync with WCF service on IIS? RRS feed

  • Question

  •  

    Absolutely no luck with with setting up a mobile client (WM6) to work successfully with WCF service on IIS 7.0 and SQL Server 2008 RC0. Would be nice to know if any got any success in a similar setup and what step did he/she took.

    Desktop client has no problem consuming the service, so it's functioning properly.

    Are there any official mobile tutorial/doc?

    • Moved by Hengzhe Li Friday, April 22, 2011 3:28 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Tuesday, June 17, 2008 3:54 PM

Answers

  •  

    Hi Folks, I have been keeping an eye on this thread for a couple of weeks and has been playing with the WCF config for a mobile application on and off for a couple of days and I have put soem tips to config the WCF service for Mobile application. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3609978&SiteID=1

     

    I hope this can provide some help here and easy up some pain you guys had with native support of WCF in netcf.

     

    thanks

    Yunwen

    Sunday, July 13, 2008 4:33 PM
    Moderator

All replies

  • Hi,
    I implemented a n-tier scenario which work fine but with older tehcnologies ... For the docs this is the best i found :
    http://alexduggleby.com/category/sync-framework/
    http://www.syncguru.com
    http://www.techheadbrothers.com/Articles.aspx/introduction-microsoft-synchronization-framework

    The last one is in french. I think you can find what you need in one of the two first.

    Regards

    Sam
    Wednesday, June 18, 2008 6:46 PM
  •  

    What technologies did you use? I've been using web services for synchronization with devices before, but decided to go for the latest and gratest from MS and so far failed.
    Friday, June 20, 2008 8:37 AM
  • Hi,
    for my part i used sqlce 3.5, sql server 2005, visual studio 2005, IIS 6.0 and windows server 2003.
    If i remember good the links that i provide to you, the 2 first correspond to that technological scenario, and the third tutorial correspond to 2008 technologies. So i am sorry i can t give you any help with the latest techs.

    Regards

    Sam
    Friday, June 20, 2008 10:13 PM
  • If you describe the issues that you have encountered perhaps we can assist.  I assume that you have downloaded the device samples at the following location:

     

    http://www.microsoft.com/downloads/details.aspx?FamilyId=75FEF59F-1B5E-49BC-A21A-9EF4F34DE6FC&displaylang=en

     

    Sean Kelley

    Microsoft

    Program Manager

     

    Friday, June 20, 2008 11:54 PM
    Moderator
  • Yep, that sample works. But I don't see that it describes anywhere how to consume a WCF service, how to create a working reference with netcfsvcutil and then modify it so that it works.

     

    Here's the steps I've taken so far:

    1. Create a Windows Forms Application

    2. Add Local Database Cache with both Client and Server code in the same project.

    3. Set up a simple snapshot sync:

     

    Code Snippet

    Dim syncAgent As New SyncClient.DataCacheSyncAgent

    syncAgent.SomeTable.SyncDirection = SyncDirection.Snapshot

    Dim syncStats As SyncStatistics = syncAgent.Synchronize()

    SomeDataSet.SomeTable.Merge(SomeTableAdapter.GetData())

     

    That works up till now.

    4. Add s WCF Service Library project.

    5. Move Server code through the designer to this new project

    6. Add service config to App.config:

     

    Code Snippet

    <system.serviceModel>

    <services>

    <service behaviorConfiguration="SyncService.DataCacheSyncServiceBehavior"

    name="SyncService.DataCacheSyncService">

    <endpoint address=http://someHost:8080/Sync.svc binding="basicHttpBinding" bindingNamespace=http://someHost:8080/

    contract="SyncService.IDataCacheSyncContract" />

    <host>

    <baseAddresses>

    <add baseAddress=http://someHost:8080/ />

    <add baseAddress=http://192.168.1.2:8080/ />

    </< FONT>baseAddresses>

    </< FONT>host>

    </< FONT>service>

    </< FONT>services>

    <behaviors>

    <serviceBehaviors>

    <behavior name="SyncService.DataCacheSyncServiceBehavior">

    <serviceMetadata httpGetEnabled="True" />

    <serviceDebug includeExceptionDetailInFaults="False" />

    </< FONT>behavior>

    </< FONT>serviceBehaviors>

    </< FONT>behaviors>

    </< FONT>system.serviceModel>

     

    7. Manually create Sync.svc (I'll need a factory later):

     

    Code Snippet

    <%@ ServiceHost Service="SyncService.DataCacheSyncService" Debug="true" %>

     

     

     

    8. Create a new site in IIS (7.0 on WS 2008) and publish the service there (http://someHost:8080/)

    9. Add Service Reference to Windows Forms Application pointing at http://someHost:8080/Sync.svc

    10. Modify sync code to use proxy:

     

    Code Snippet

    Dim syncAgent As New SyncClient.DataCacheSyncAgent(New DataCacheSyncContractClient)

     

    Up till now synchronization works. So now for the fun part.

     

    11. Create a Smart Device Project and add references to Microsoft.Synchronization, Microsoft.Synchronization.Data(for Devices), etc.

    12. Copy .sdf and .sync from desktop client

    13. Generate device references with netcfsvcutil:

     

    Code Snippet
    netcfsvcutil /language:vb http://192.168.1.2:8080/Sync.svc

     

    14. Clean-up Service.vb, remove all repeated types and import Microsoft.Synchronization and Microsoft.Synchronization.Data

    15. Now try to add XmlSerializerFormat to methods in ISyncContract interface (as somebody suggested before) and when calling Synchronize in desktop client get:

    "Value cannot be null. Parameter name: syncSchema"

    So must be a wrong place.

    16. Now try add XmlFormatSerializer to SyncContract's methods instead of its interface's and the desktop client works without any issues now. So this is probably the right place.

    17. Use same code as in desktop client for sync in device client... and get "CFFaultException" in InnerException with:

     

    Code Snippet

    a:DeserializationFailedThe formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:syncSessionhttp://tempuri.org/:syncSession">http://tempuri.org/:syncSession</A< A>>. The InnerException message was 'Error in line 1 position 451. 'EndElement' 'syncSession' from namespace 'http://tempuri.org/' is not expected. Expecting element '_clientId'.'.  Please see InnerException for more details.

     

    Similar message when trying to reference the service as a Web Service.

     

    Tools used:

    Server: WS 2008, SQL Server 2008 RC0 with whatever version of Sync Services it comes with

    Dev: VS 2008 SP1 Beta, WM 6 SDK Refresh and Sync Services for Devices CTP1

    Monday, June 23, 2008 11:01 AM
  • Any updates on this?

     

    Tuesday, June 24, 2008 1:47 PM
  • Sync Services Forum has been like a confession in a church so far: people only go there once they have problems and God is never there

    Wednesday, June 25, 2008 4:59 AM
  • So is it possible at present time to consume a WCF service in device projects without first wrapping it in web service and writing your own proxy?

    Saturday, June 28, 2008 8:25 AM
  • Did you ever resolve the CFFaultException as I am getting the same exception:

    aBig SmileeserializationFailedThe formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/Tongue TiedyncSessionhttp://tempuri.org/Tongue TiedyncSession"

    Thanks

    Friday, July 4, 2008 10:08 PM
  • Nope. I wrote a web service wrapper for WCF service and custom proxy to consume it on client side. So far no idea how to use WCF service natively in .NET CF.

    Saturday, July 5, 2008 10:30 AM
  • Can I safely assume now that dev team don't give a **** about their target userbase and issues they (users) meet when they want to use Sync Services? How much time would it take to write a small reply once a week? There're aren't that much threads? Unless of course what I'm asking for is not really possible right now. But in that case a simple explanation of why not would work. By simply ignoring this case you're just proving the point that it's best to avoid new MS technologies at all costs. But then who are you targeting?

    So far this forum has been the definition of the word "useless".

    You can now close this thread and ban me. Doesn't matter.

    Tuesday, July 8, 2008 8:47 AM
  •  

    Hi Folks, I have been keeping an eye on this thread for a couple of weeks and has been playing with the WCF config for a mobile application on and off for a couple of days and I have put soem tips to config the WCF service for Mobile application. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3609978&SiteID=1

     

    I hope this can provide some help here and easy up some pain you guys had with native support of WCF in netcf.

     

    thanks

    Yunwen

    Sunday, July 13, 2008 4:33 PM
    Moderator
  • Hi, I just developed a sample test program that uses a WCF service to sync a database served by SqlServer 2008 with a local SqlServer CE 3.5 database cache running on WM6.

     

    Follow this http://www.youdev.net/post/2008/09/30/WCF-Synchronization-between-Desktop-and-Mobile-Applications.aspx.

     

    Hope can help!

    Friday, October 3, 2008 10:25 PM


  • Hi all,

    You might find the following MSDN walkthrough some help (
    Creating an Occasionally Connected Smart Device Application):

    http://msdn.microsoft.com/en-gb/library/cc488004.aspx

    Take care to read the Community Content at the bottom though which highlights the problems and fills in some of the missing code.

    One other problem I had was the device/emulator not being able to find the remote host when syncing - my solution was to replace the host name with its IP address in the generated Web Reference class (in Reference.cs). The relevant code ended up like so:

    public NorthwindSyncService() {
       this.Url = "http://192.168.1.25:8731/Design_Time_Addresses/OCSServiceApp/NorthwindSyncService/";
       }

    I also found the posts from Yunwen and adospace very helpful - thanks guys!

    Wednesday, November 5, 2008 10:16 AM
  • Hi All,

    Please Fallow the steps.

    In VS2008

    1. Please create one Smart Device Application.

    2. Add  WCF Service Library project .

    3. In WCF Service Library Project we have "IService1.cs" and  "Service1.cs" .

    4.Please replace the following code in "IService1.cs"

    [

    XmlSerializerFormat()]// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.

    [

    ServiceContract]

     

    public interface IService1

    {

    [

    OperationContract()]

     

    SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession);

    [

    OperationContract()]

     

    SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);

    [

    OperationContract()]

     

    SyncSchema GetSchema(Collection<string> tableNames, SyncSession syncSession);

    [

    OperationContract()]

     

    SyncServerInfo GetServerInfo(SyncSession syncSession);

    }

    5.Please Add Following reference to WCF Service Library Project

    1.Microsoft.Synchronization.Data;
    2.System.Data.SqlClient;
    3. System.Data;
    4.System.Collections.ObjectModel;

    6. Please replace following code in "Service1.cs"

    public

    class Service1 : IService1

    {

     

    private LocalDataCache1ServerSyncProvider _serverSyncProvider = new LocalDataCache1ServerSyncProvider();

     

     

     

    [System.Diagnostics.

    DebuggerNonUserCodeAttribute()]

     

    public virtual SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession) {

     

    return this._serverSyncProvider.ApplyChanges(groupMetadata, dataSet, syncSession);

    }

     

    [System.Diagnostics.

    DebuggerNonUserCodeAttribute()]

     

    public virtual SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession) {

     

    return this._serverSyncProvider.GetChanges(groupMetadata, syncSession);

    }

     

    [System.Diagnostics.

    DebuggerNonUserCodeAttribute()]

     

    public virtual SyncSchema GetSchema(Collection<string> tableNames, SyncSession syncSession) {

     

    return this._serverSyncProvider.GetSchema(tableNames, syncSession);

    }

     

    [System.Diagnostics.

    DebuggerNonUserCodeAttribute()]

     

    public virtual SyncServerInfo GetServerInfo(SyncSession syncSession) {

     

    return this._serverSyncProvider.GetServerInfo(syncSession);

    }

    }

     

    7. Please Add  "Local Database Cache" to WCF Project.

     1.right Click on WCF Project-->Add New Item--> select "Local Database Cache"

     2. In Configure Data Synchronization Dialog box  Create New Server connection.

      3. Automatically Client Connection will create.

      4. Than Press Add Button  there you can select the database tables and then press "OK"

      5.Then We will back to "Configure Data Synchronization Dialog box " 

      6. In this we have "Advanced Button" click this button

      7. It will show two options 1. Server Project Location 2. Client Project Location

      8.In "Server Project Location " select "WCF Project" 

      9. In Client Project Location" Select "Smart Device Projcet"

      10.Then Press "OK" button.

      11. go to the "App.config" file  replace the code with following code.

    <?

    xml version="1.0" encoding="utf-8" ?>

    <

    configuration>

    <

    system.web>

    <

    compilation debug="true" />

    </

    system.web>

    <!--

    When deploying the service library project, the content of the config file must be added to the host's

    app.config file. System.Configuration does not support config files for libraries.

    -->

    <

    system.serviceModel>

    <

    services>

    <

    service name="WcfServiceLibraryTest.Service1" behaviorConfiguration="WcfServiceLibraryTest.Service1Behavior">

    <

    host>

    <

    baseAddresses>

    <

    add baseAddress = http://IPAddress:8731/WcfServiceLibraryTest/Service1/ />

    </

    baseAddresses>

    </

    host>

    <!--

    Service Endpoints -->

    <!--

    Unless fully qualified, address is relative to base address supplied above -->

    <

    endpoint address ="" binding="basicHttpBinding" contract="WcfServiceLibraryTest.IService1">

    <!--

    Upon deployment, the following identity element should be removed or replaced to reflect the

    identity under which the deployed service runs. If removed, WCF will infer an appropriate identity

    automatically.

     

    -->

    <

    identity>

    <

    dns value=IPADDRESS"/>

    </

    identity>

    </

    endpoint>

    <!--

    Metadata Endpoints -->

    <!--

    The Metadata Exchange endpoint is used by the service to describe itself to clients. -->

    <!--

    This endpoint does not use a secure binding and should be secured or removed before deployment -->

    <

    endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

    </

    service>

    </

    services>

    <

    behaviors>

    <

    serviceBehaviors>

    <

    behavior name="WcfServiceLibraryTest.Service1Behavior">

    <!--

    To avoid disclosing metadata information,

    set the value below to false and remove the metadata endpoint above before deployment

    -->

    <

    serviceMetadata httpGetEnabled="True"/>

    <!--

    To receive exception details in faults for debugging purposes,

    set the value below to true. Set to false before deployment

    to avoid disclosing exception information

    -->

    <

    serviceDebug includeExceptionDetailInFaults="False" />

    </

    behavior>

    </

    serviceBehaviors>

    </

    behaviors>

    </

    system.serviceModel>

    </

    configuration>


    -----

    In this "WcfServiceLibraryTest" is the name of WCF Service Library project.

    12. add .SVC File to  WCF Project and name as "Service1.svc"

    13 . Replace the following by "Service.svc"

    <%

    @ ServiceHost Service="WcfServiceLibraryTest.Service1" Debug="true" %>

    <%

    @ Assembly Name="WcfServiceLibraryTest" %>

     

    14.Now we have to generate Proxy Classes to WCF Project.

    15.We can generate Proxy classes in two ways.

      15.1 By using IIS

      15.2 With out IIS ( using NetCFSvcUtil)

    15.1 By using IIS

      1. Create Virtual Directory  for the WCF Project 

       2. In IE Browse http://IPAddress/VirtualDirectoryName/Service.svc

       3. Please Copy the IP Address Provided by IE 

       4.Go To the Smart Device Project and hen rightClick-->Add  Web References-> Paste the path specified in IE.

    15.2 With Out IIS

      1. using NetCFSvcUtil.exe we can generate  two  Proxy classes (CFClientBase.cs,Service1.cs)

       2. Add these two classes to Samrt device Project.

    Thanks
    Lakshmi Narayana





     





     
     



     

    Thursday, April 9, 2009 10:13 AM