[英]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. 我必须在WPF应用程序中使用Sync Framework 2.0,该应用程序将包含SQL Compact 3.5,并将与SQL Server 2008同步。
I followed this video : http://download.microsoft.com/download/6/7/3/6730f0e7-a649-4656-96ab-150c7501a583/IntroToSyncServicesADODetNet_HighQuality.wmv .
我观看了此视频: 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#. 但是我使用EntityFramework 4.0和C#代替了DataSet。
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. 当我在WPF应用程序中拥有用于客户端和服务器的代码时,一切正常。
Everything works grate when I use WCF Class Library that contains server synchronization logic. 当我使用包含服务器同步逻辑的WCF类库时,一切正常。
But... In the following example they show us how to run solution and host WCF in local "WCF Host" only on my computer. 但是...在下面的示例中,他们向我们展示了如何仅在我的计算机上运行解决方案并在本地“ WCF主机”中托管WCF。
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."
“如何从包含所有服务器同步逻辑的WCF类库中创建类的实例,然后承载它并在ASP.NET MVC 2.0应用程序中公开。”
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. 最重要的是保留此* .sync文件,而不是手动编写所有代码,这使我可以选择在数据库架构更改时自动更新此代码。
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?..."
“当在类库中的WCF类库实例位于app.config中时,如何在我的web.config中为该WCF类库实例配置端点和行为?...”
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. 不幸的是,*。sync文件的向导只能看到本地WPF应用程序或WCF类库,我无法直接选择ASP.NET MVC 2.0(这很好)来生成用于在Web应用程序中进行同步的类。
I would be very pleased to see working example. 我很高兴看到工作示例。
Regards, Daniel Skowroński 此致DanielSkowroński
Solution to create WCF Class Library instance with synchronization logic hosted in ASP.NET MVC 2.0: 使用ASP.NET MVC 2.0中托管的同步逻辑创建WCF类库实例的解决方案:
follow http://download.microsoft.com/download/6/7/3/6730f0e7-a649-4656-96ab-150c7501a583/IntroToSyncServicesADODetNet_HighQuality.wmv to create WCF Class Library 遵循http://download.microsoft.com/download/6/7/3/6730f0e7-a649-4656-96ab-150c7501a583/IntroToSyncServicesADODetNet_HighQuality.wmv创建WCF类库
create ASP.NET MVC 2.0 App and add WCF Service 创建ASP.NET MVC 2.0应用并添加WCF服务
delete C# file *.cs behind *.svc 删除* .svc后面的C#文件* .cs
add Project Referece from ASP.NET projet to WCF Class Library 将来自ASP.NET projet的Project Referece添加到WCF类库
edit your *.svc file in ASP.NET 在ASP.NET中编辑* .svc文件
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" 其中Service是Factory方法,它将创建“ namespace-assembly.class”的实例,因此,您必须将其更改为“ wcf_librrary_namespace-assembly。**** DataCacheSyncService”,并将CodeBehind更改为“ 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 接下来,在WCF类库中修改wcf实例,使其能够使用与asp.net应用程序相同的凭据托管它,只需添加:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]属性
next configure web.config: 接下来配置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 现在只需将其发布到您的服务器并创建ASP.NET应用
now add Service Reference to your Client Application 现在将服务参考添加到您的客户端应用程序
here we have problem that when you will execute: 在这里,我们有一个问题,当您执行时:
**DataCacheSyncAgent syncAgent = new **DataCacheSyncAgent(new **DataCacheSyncContractClient()); ** DataCacheSyncAgent syncAgent =新** DataCacheSyncAgent(新** DataCacheSyncContractClient());
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize(); 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. 您可能会得到异常:“无法将类型**转换为Microsoft.Synchronization.Data.SyncGroupMetadata,目前为止我发现的解决此问题的一种方法是扩展服务引用,然后b CTR + H重命名所有“ asp- net-assembly-SyncGroupMetadata”和“ Microsoft.Synchronization.Data.SyncGroupMetadata”等其他文件。
HTH HTH
Regards, 问候,
Daniel Skowroński 丹尼尔·斯科文斯基
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.