"复制的"班WCF代理code [英] "Copied" classes in WCF proxy code

查看:151
本文介绍了"复制的"班WCF代理code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用WCF和Visual Studio 2008来构建一个大型的,分布式应用程序。我们没有与WCF,所以我们正在投资一些时间原型客户端和服务器之间的通信WCF太多的经验。我们观察到,由WCF服务,我们的服务器子系统作为一个参数或返回类型引用的任何类是复制到通过产生的code Visual Studio中的客户端代理。我发现令人惊讶的是,这样做的时候,Visual Studio中改变了类的命名空间。例如,假设我有以下的code:

We are using WCF and Visual Studio 2008 to build a large, distributed application. We don't have much experience with WCF so we are investing some time in prototyping the WCF communications between clients and server. We have observed that any class referenced by the WCF services in our server subsystem as a parameter or return type is "copied" into the client proxy by Visual Studio through generated code. What I found surprising was that, when doing this, Visual Studio alters the namespace of the classes. For example, imagine that I have the following code:

namespace MyLibrary
{
    class MyClass
    {
        //...
    }
}

和想象,我编译成 MyLibrary.dll ,到我的WCF服务有一个参考。我的一些WCF服务使用 MyLibrary.MyClass 作为返回类型。当我看到生成的客户端代理code,我觉得 MyClass的将自动地提供(这是凉),但它不是在在MyLibrary 命名空间由Visual Studio了,但在一个生成的。

And imagine that I compile that into MyLibrary.dll, to which my WCF services have a reference. Some of my WCF services use MyLibrary.MyClass as a return type. When I look at the generated client proxy code, I find MyClass to be automagically available (which is cool), but it is not in the MyLibrary namespace anymore but in one generated by Visual Studio.

我们正计划与数百名在多个组件分布类复杂的域对象模型,我关注的是如何好这个会端口穿越code一代的Visual Studio一样。另外,我很担心,所有我们设计的命名空间的层次好看将可能丢失。我们最初的设想是建立类库的领域对象模型和delpoy其服务器和客户端上。但由于WCF魔力似乎产生code进行必要的课程,我想会有冲突,如果我们在客户端上部署我们自己的库。

We are planning to have a complex domain object model with hundreds of classes distributed across multiple assemblies, and I am concerned about how well this will "port" across the code generation that Visual Studio does. Also, I am concerned that all the nice hierarchy of namespaces that we have designed will be probably lost. Our initial vision was to create class libraries for this domain object model and delpoy it on both server and client. But since WCF magic seems to generate code for the necessary classes, I imagine that there would be a conflict if we deploy our own libraries on the client.

我有两个具体的问题,然后:

I have two specific questions then:


  • 有没有一种方法,使生成客户端代理code时,Visual Studio中使用原来的命名空间方案,而不是自己的?如果没有,这会不会影响我们的抄袭库中的可用性在客户端上?

  • 我可以部署在客户端上仍原库?我想不会,但什么样的冲突将这项事业?

感谢您。

推荐答案

当你添加你可以点击高级按钮,在那里你可以检查,上面写着中引用的组件重用类型框服务引用。您还需要确保你有一个包含在客户端项目中引用原始类型的程序集。

When you add a service reference you can click the "Advanced" button, in there you can check the box that reads "Reuse types in referenced assemblies". You will also need to make sure you have the assembly that contains the original types referenced in the client project.

您当然可以在客户端上部署原始库。

You can of course deploy the original libraries on the client.

究其原因WCF做到这一点 - 这个概念的服务可以通过不具有原始的二进制文件,甚至不支持.NET(如Java的)的客户端消耗 - 因此服务边界发布一切客户需要,以调用它,并处理其响应。

The reason WCF does this - the concept is that the services could be consumed by a client that doesn't have your original binaries, or even doesn't support .net (e.g. Java) - therefore the service boundary publishes everything a client would need in order to call it, and deal with its response.

这篇关于"复制的"班WCF代理code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆