简体   繁体   English

类库,Silverlight和Web服务

[英]Class Libraries, Silverlight and Webservices

I have a Silverlight Class Library that I want to use in both my Silverlight and my WebService project. 我有一个想要在Silverlight和WebService项目中使用的Silverlight类库。

I am able to create and reference the Library in both projects without any problems, but when I try to use any of the classes in the Library on the Silerlight project, I get an ambiguous reference error between my Library and the Asmx Webservice (apparently, the silverlight project believes that the classes in the class library exist in the webservice). 我可以在两个项目中创建和引用库而不会出现任何问题,但是当我尝试在Silerlight项目上使用库中的任何类时,我的库和Asmx Web服务之间出现了模棱两可的引用错误(显然, silverlight项目认为类库中的类存在于Web服务中。

How can I correct this issue? 我该如何解决这个问题? I have tried rebuilding and cleaning, but it does not seem to work. 我已经尝试过重建和清洁,但是似乎没有用。 Can anyone help? 有人可以帮忙吗?

Sounds like the objects you are passing to Silverlight, via the WCF service, are the same objects in your class library. 听起来像您通过WCF服务传递给Silverlight的对象与类库中的对象相同。 In that case the generated web-reference objects will be given the same names. 在这种情况下,生成的网络参考对象将被赋予相同的名称。 Linking with the library will then give you 2 sets of objects with the same names. 与库链接将为您提供2组具有相同名称的对象。

If you install RIA services, once feature is the ability to share code between client and server by simply adding ".shared" in the class filenames before the extensions. 如果您安装RIA服务,则只需通过在扩展名之前的类文件名中添加“ .shared”,即可在客户端和服务器之间共享代码。 ASMX services are so last century :) 上世纪 ASMX服务是如此 :)

if you don't want to learn the RIA services way of sharing objects across the great-web-divide (which I would recommend), you need to separate the data objects from the functionality you actually want to share client and server side. 如果您不想学习跨大型网络共享对象的RIA服务方式(我建议这样做),则需要将数据对象与实际要共享客户端和服务器端的功能分开。

To give more specific advice on your current set-up I would need to see more about how it is structured. 要针对您当前的设置提供更具体的建议,我需要了解更多有关其结构的信息。

A technique you can use is aliasing your using statements: 您可以使用的一种技术是为using语句添加别名:

using MyNameSpace = My.Name.Space;
using MyWebService = My.Web.Service;

Then access all of your objects with these aliases to remove the ambiguities. 然后使用这些别名访问所有对象以消除歧义。

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

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