强制 .NET webservice 使用本地对象类,而不是代理类 [英] Force .NET webservice to use local object class, not proxy class

查看:29
本文介绍了强制 .NET webservice 使用本地对象类,而不是代理类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 windows 窗体应用程序调用的 web 服务(都是 .NET,都在同一个解决方案中),我希望我的 web 服务从项目的​​其他地方返回一个自定义对象 - 这是一个常见的他们都共享一个引用的对象,因为它在我的解决方案的第三个项目中.当我调用 webservice 时,它​​返回一个Person"对象,但它位于 webservice 的命名空间中,并且它是从 webservice 本身生成的代理类创建的.因此,我无法操作它并将其返回给我的程序,该程序需要基于类的共享副本的Person"对象,而不是来自 webservice 命名空间的代理副本,并且在尝试时出现错误将其 CType 为正确的类类型.

I have a webservice that I'm calling from a windows forms application (both .NET, both in the same solution), and I'd like my webservice to return a custom object from elsewhere in the project - it's a common object that they both share a reference to, as it's in the third project in my solution. When I call the webservice, it returns a "Person" object, but it's in the namespace of the webservice, and it's created from a proxy class that the webservice itself generated. As such, I can't manipulate it and return it to my program, which is expecting a "Person" object based on the shared copy of the class, not a proxy copy from the webservice namespace, and I get an error when I try to CType it to the correct class type.

如何强制网络服务使用类的本地副本,而不是代理副本?我的问题在这种情况下有意义吗?如果没有,我会澄清的.

How do I force the webservice to use a local copy of the class, not a proxy copy? Does my question make any sense in this context? If not, I'll clarify it.

值得注意的是 - 我已经通过传递所有参数 ByRef,并使用这些返回值来填充我在返回时创建的对象的副本.这不是最好的方法!

Of note - I've resorted to passing all of the parameters ByRef, and using those returned values to populate a copy of the object I create upon return. That can't be the best way to do this!

推荐答案

如果您使用 svcutil.exe 生成 WCF 客户端代理,则可以在命令行上使用/reference 来指定包含公共类的程序集.Svcutil 应重用该类定义,而不是在服务代理命名空间中生成新的类定义.

If you are using svcutil.exe to generate a WCF client proxy, you can use /reference on the command-line to specify the assembly containing the common class. Svcutil should reuse that class definition instead of generating new one in the service proxy namespace.

此外,这仅在您的公共类可序列化并按值传递时才有效(即它作为数据合同公开,而不是作为服务合同公开).

Also, this will work only if your common class is serializable and passed by value (i.e. it's exposed as a data contract, not as a service contract).

这篇关于强制 .NET webservice 使用本地对象类,而不是代理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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