简体   繁体   English

Silverlight应用程序中的RIA服务代码生成

[英]RIA Services Code Generation in Silverlight application

Is there any way to avoid code generation for types that are already referenced when using multiple domains? 有什么方法可以避免在使用多个域时为已引用的类型生成代码?

Let me explain. 让我解释。


I have an application infrastacture for silverlight application. 我有Silverlight应用程序的应用程序基础结构。 This infra package includes 3 (RIA) domain services (authentication, logging, service discovery) on the server side - Infra.Web.dll and a silverlight dll - ClientInfra.dll that implements user authentication at the application start and some other base classes (like BaseApp and BaseView) while Infra.Web.dll is defined as WCF RIA Services Link for ClientInfra.dll . 该基础设施包在服务器端包括3个(RIA)域服务(身份验证,日志记录,服务发现) -Infra.Web.dll和silverlight dll- ClientInfra.dll ,它们在应用程序启动时实现用户身份验证以及一些其他基类( (例如BaseApp和BaseView),而Infra.Web.dll被定义为ClientInfra.dll的 WCF RIA服务链接。

Now I'm developping some demo silverlight application in order to test my infrastructura. 现在,我正在开发一些演示Silverlight应用程序,以测试我的基础设施。 I have created the 我已经创建了

DemoApp.Web wich refernces the Infra.Web.dll (in order to get the infra services) DemoApp.Web引用Infra.Web.dll (以获取基础服务)

and 2 silverlight projects: 和2个Silverlight项目:

DemoApp.Data that defines DemoApp.Web.dll as WCF RIA Services Link in order to get the generated code and refrences ClientInfra.dll 将DemoApp.Web.dll定义为WCF RIA服务链接的DemoApp.Data ,以获取生成的代码并刷新ClientInfra.dll

DemoApp that is the actual silverlight application that refernces ClientInfra.dll DemoApp引用 ClientInfra.dll的实际Silverlight应用程序

The problem is that when I try to use one of the RIA services from the silverlight application I've got an error that the Domain Service classes are defined both in ClientInfra.dll and DemoApp.Data . 问题是,当我尝试使用silverlight应用程序中的RIA服务之一时,出现一个错误,即ClientInfra.dllDemoApp.Data中都定义了域服务类。 As far as I understand the problem is the code from Infra.Web.dll has been generated twice: first for ClientInfra.dll , second for DemoApp.Data . 据我了解,问题是Infra.Web.dll的代码已生成两次:第一是ClientInfra.dll ,第二是DemoApp.Data

Is there any way to avoid code generation for types that are allready refrenced like in my case where ClientInfra.dll allready has the generated infra services so there is no need to generate it again in DemoApp.Data ? 是否有任何方法可以避免为已经全部刷新的类型生成代码,例如在我的情况下, ClientInfra.dll allready具有生成的基础结构服务,因此无需在DemoApp.Data中再次生成它?

I'll try to make my question more simple. 我将尝试使我的问题更简单。 How can I avoid the ria services type generation (in silverlight) of types that have been already generated for my referenced dll? 如何避免为参考dll已经生成的类型的ria服务类型生成(在Silverlight中)? The type generation duplication causes an error CS0433 that the same types are defined in 2 different dll's 类型生成重复导致错误CS0433,即在2个不同的dll中定义了相同的类型

I have found out some interesting fact. 我发现了一些有趣的事实。 If I reference the ClientInfra.dll directly from the DemoApp (the silverlight application project) than the data types that have been alresdy generated in ClientInfra.dll are not generated once more. 如果我直接从中的demoApp(Silverlight应用程序项目)比已在ClientInfra.dll被alresdy产生的数据类型引用ClientInfra.dll不会产生一次。 But if I reference the ClientInfra.dll from DemoApp.Data I do get the duplicated types code generation with a compilation warning that the same types are defined both in the referenced dll and in the generated code. 但是,如果我从DemoApp.Data引用ClientInfra.dll则会得到重复类型的代码生成,并带有编译警告,指出在引用的dll和生成的代码中都定义了相同的类型。

I have found the following in the msdn documentation 我在msdn文档中找到了以下内容

Analyze all assemblies either built or referenced by the middle tier project for domain service classes, entity classes, or shared code. 分析由中间层项目构建或引用的所有程序集,以获取域服务类,实体类或共享代码。

RIA Services checks the existing members before generating the proxy class. RIA Services在生成代理类之前会检查现有成员。 Any member that is already defined will not be generated in the proxy class. 代理类中不会生成任何已定义的成员。

That means that my scenario should work as I have expected! 这意味着我的方案应该按预期工作!

In order to check the code generation process I set the MSBuild project to build output verbosity (Tool->Options->Projects and Solutions->Build and Run) to Normal (instead of default Minimal). 为了检查代码生成过程,我将MSBuild项目设置为将输出详细程度 (工具->选项->项目和解决方案->生成并运行)设置为正常(而不是默认的最小)。 Then after the compilation I discovered that the DemoApp.Data project had failed to load ClientInfra.dll that includes already generated proxies. 然后,在编译之后,我发现DemoApp.Data项目无法加载包含已经生成的代理的ClientInfra.dll So the generator just ignored it and generated all the classes from the beginning. 因此,生成器只是忽略了它,并从一开始就生成了所有类。

I have solved this loading issue and everything works fine now. 我已经解决了这个加载问题,现在一切正常。

我有一个类似的基础结构,但是我使用SOAP公开了DomainServices并在其他应用程序中使用了这些服务,因此,我应该对您的项目执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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