WCF 4.0 & Sync Framework 2.0 & Entity Framework 4.0 & ASP.NET MVC 2.0 & Auto Generated Code

I need to use Sync Framework 2.0 in our WPF application which will contain SQL Compact 3.5 and will sync with SQL Server 2008.

I followed this video: http://download.microsoft.com/download/6/7/3/6730f0e7-a649-4656-96ab-150c7501a583/IntroToSyncServicesADODetNet_HighQuality.wmv .

But instead of DataSet, I used EntityFramework 4.0 and C #.

I am very interested in generating code by adding a Local Database Cache file with sync extension. This is great, and I can change the code in my partial class to change the underlying functionality.

Everything works when I have the code for the client and server location in a WPF application.

Everything works when I use the WCF class library which contains the server synchronization logic.

But ... In the following example, they show us how to run the solution and host WCF in a local "WCF Host" only on my machine.

First question:

"How to instantiate a class from a WCF class library that contains all the server synchronization logic, and then host and expose it in an ASP.NET MVC 2.0 application."

The most important thing is to save these * .sync files and not write all the code by hand, this gives me the ability to automatically update this code when the database schema changes.

Second question:

"How do I configure endpoints and behavior for this instance of WCF class library in my web.config when it has its app.config file in class library? ..."

Unfortunately, the wizard for * .sync files only sees the local WPF application or WCF class library, I can't choose to directly ASP.NET MVC 2.0 (would be great) generate the class for synchronization in the web application.

I would be very pleased to see a working example.

Best regards, Daniel Skorowski

+2


a source to share


1 answer


Solution to instantiate WCF class library with synchronization logic hosted in ASP.NET MVC 2.0:

here you will see something like:

 <%@ ServiceHost Language="C#" Debug="true" Service="namespace-assembly.class" CodeBehind="filename.svc.cs" %>

      

where Service is a Factory method that will instantiate "namespace-assembly.class", so you must change it to "wcf_librrary_namespace-assembly." DataCacheSyncService "and" CodeBehind "to" wcf_librrary_namespace-assembly.filename ".cs"

  • next change the wcf instance in the WCF class library to accommodate it with the same credentials as the asp.net application, just add: [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] attribute

  • next configure web.config:

    <service name="asp.net-namespace.wcf_service_name" behaviorConfiguration="service_nameBehavior">
      <host>
         <baseAddresses>
            <add baseAddress="http://ipaddres/asp.net-app-name/service-name.svc" />
         </baseAddresses>
      </host>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <endpoint address=""  binding="basicHttpBinding" contract="wcf_librrary_namespace assembly.I****DataCacheSyncContract" />
    </service>
    
    <behavior name="service_nameBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    
          

add also

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 

      

below



<system.serviceModel>

      

  • now just publish it to your server and create ASP.NET application

  • now add the service link to your client app

  • here we have a problem when you do:

    ** DataCacheSyncAgent syncAgent = new ** DataCacheSyncAgent (new ** DataCacheSyncContractClient ());

Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize ();

You will probably get an exception: "Unable to convert type ** to Microsoft.Synchronization.Data.SyncGroupMetadata. One solution to this problem at the moment I found out is to extend your service link and b CTR + H rename everything" asp -net-assembly-SyncGroupMetadata "and other similar files in" Microsoft.Synchronization.Data.SyncGroupMetadata "etc.

  • Synchronization should now start

NTN

Hello,

Daniel Skorowski

+1


a source







All Articles