Silverlight / WCF 中的数据传输对象令人遗憾

发布于 2024-09-27 05:47:33 字数 390 浏览 1 评论 0 原文

我有一个托管在 Azure Web 角色 ASP 项目中的 Silverlight 应用程序。 ASP 项目公开了 WCF 服务。

我想要一组数据类型的类定义。有人建议创建第三个项目(类库)并从 SL 和 ASP 添加对它的引用。我开始这样做,但 Silverlight 项目抱怨说您只能添加对 Silverlight 项目的引用。

然后我创建了一个 Silverlight 类库并将数据类移至其中。不过,我添加了一些 .dll 引用,例如 Windows Azure 存储客户端。然后 Silverlight 类库告诉我只能添加对 Silverlight 4 友好的 .dll 的引用,而 Windows Azure 不是其中之一。极好的。

我可以采取什么措施来解决这个问题,还是我只能采用不太优雅、冗余的解决方案?

I have a Silverlight app hosted in an Azure web role ASP project. The ASP project exposes a WCF service.

I would like to have one set of class definitions for the data types. Someone recommended making a third project (class library) and adding a reference to it from the SL and ASP. I started doing this, but the Silverlight project complained that you can only add references to Silverlight projects.

I then made a Silverlight class library and moved the data classes to it. However, I to add some .dll references, like to the Windows Azure storage client. Then the Silverlight class library tells me I can only add references to Silverlight 4-friendly .dlls, of which Windows Azure isn't one. Fantastic.

Is there something I can do to get around this, or am I stuck with a less elegant, redundant solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙沙粒小 2024-10-04 05:47:33

多目标是您最好的选择。 Microsoft 的 Visual Studio 中有一篇文章解释了这一点:
http://msdn.microsoft.com/en-us/ library/ff921092(PandP.20).aspx

基本上,您创建 Silverlight 和标准 .NET 类库,每个类库具有不同的名称,然后在每个类库中包含相同的文件。通常,这些文件实际上仅位于其中一个类库中,然后软链接到第二个类库中。

关键是确保文件中的代码与两个运行时兼容。如果根据运行时需要对某些方法进行单独的实现,那么您需要使用编译指示将它们分开(即#ifdef SILVERLIGHT ...)。

但是,如果您只处理数据结构,只要 Silverlight 支持您正在使用的对象,就不应该有任何问题。

Multi-targeting is your best bet. There is an article explaining this in Visual Studio from Microsoft at:
http://msdn.microsoft.com/en-us/library/ff921092(PandP.20).aspx

Basically, you create both your Silverlight and standard .NET class libraries, each with a different name, and then include the same files into each. Usually the files are actually only in one of the class libraries and then soft linked in the second one.

The key is to ensure that the code in your files is compatible with both runtimes. If there needs to be separate implementation for some of your methods depending on the runtime then you need to separate these with pragmas (i.e. #ifdef SILVERLIGHT...).

If you're only doing data structures, however, there should be no issues as long as Silverlight supports the objects you are using.

知足的幸福 2024-10-04 05:47:33

看看是否按照这个使用链接文件答案 适合你。

See if using linked files as per this answer does the trick for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文