简体   繁体   中英

WCF 4.0 & Sync Framework 2.0 & Entity Framework 4.0 & ASP.NET MVC 2.0 & auto generated code

I have to use Sync Framework 2.0 in our WPF app that will contain SQL Compact 3.5 and will synchronize 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 DataSet I've used EntityFramework 4.0 and C#.

I'm very interested in code auto generation by adding Local Database Cache file with extension sync. It is great, and I can modify code in my partial class to change base functionality.

Everything works grate when I have code for client and server place in WPF application.

Everything works grate when I use WCF Class Library that contains server synchronization logic.

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

The first question is:

"How can I create instance of class from WCF Class Library that contains all server synchronization logic and then host it and expose in ASP.NET MVC 2.0 application."

The most important thing is to keep this *.sync files and don't write all the code manually it gives me the option to automatically update this code when database schema would change.

The second question is:

"How can I configure endpoints and behaviors for this instance of WCF Class Library in my web.config when it has its on app.config in class library?..."

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

I would be very pleased to see working example.

Regards, Daniel Skowroński

Solution to create WCF Class Library instance 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 Factory method that will create instance of "namespace-assembly.class" so, you have to change this to "wcf_librrary_namespace-assembly.****DataCacheSyncService" and CodeBehind to "wcf_librrary_namespace-assembly.filename.cs"

  • next modify wcf instance in WCF Class Library that will enable hosting it with the same credentials as asp.net app, simply 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 simply publish it to your server and create ASP.NET app

  • now add Service Reference to your Client Application

  • here we have problem that when you will execute:

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

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

You will probably get Exception: “Cannot convert type ** to Microsoft.Synchronization.Data.SyncGroupMetadata, One solution to resolve this issue for now that I've found is to expand your service reference and b CTR+H rename all “asp-net-assembly-SyncGroupMetadata” and other similar files to “Microsoft.Synchronization.Data.SyncGroupMetadata” etc.

  • Now synchronization should start

HTH

Regards,

Daniel Skowroński

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM