问题描述
我有一个web服务,我从窗口调用窗体应用程序(包括.NET,无论是在同一个解决方案),我想我的web从其他地方的项目返回一个自定义对象 - 这是一个常见的对象,它们都共享一个参考,因为它是在我的解决方案的第三个项目。当我打电话的web服务,它返回一个人的对象,但它在web服务的命名空间,它是从生成的Web服务本身就是一个代理类创建。因此,我不能操纵它并返回给我的计划,这是基于预期的类,而不是从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.
如何强制web服务使用类,而不是一个代理副本的本地副本?请问我的问题在这方面的任何意义吗?如果没有,我会澄清它。
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客户端代理,您可以使用命令行/引用指定包含公共类的程序集。 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 Web服务使用本地对象类,而不是代理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!