如何使WCF客户端使用相同的数据类型为WCF服务数据类型、客户端、WCF

2023-09-04 01:27:03 作者:一见你就笑

我有一个.net WCF服务,服务只有.NET WCF客户端(所有的.NET 3.5,没有互联互通,通过TCP,二进制编码)。 使用svcutil.exe的所使用的服务的数据成员的复合类型中产生所使用的客户端的proxy.cs类的一部分。

I have a .NET WCF service that services only .NET WCF clients (all .NET 3.5, no interoperability, via TCP, binary encoding). Using svcutil.exe the composite types that are used by the data members of the service are generated as part of the proxy.cs class used by the clients.

然而,怎么做,如果我想引用在服务器/ WCF方声明的同类型? 场景: 3组件:client.exe,wcfobjects.dll和wcfservice.dll - >在wcfservice.dll参考wcfobjects.dll - >客户端也引用wcfobjects.dll

However, what to do if I wanted to reference the same types declared on the server/WCF side? Scenario: three assemblies: client.exe, wcfobjects.dll and wcfservice.dll --> the wcfservice.dll references wcfobjects.dll --> the client too references wcfobjects.dll

我怎样才能生成一个代理,不包括使用的服务类型? 那可能吗? 谢谢你。

How can I generate a proxy that does NOT include the types used by the service? Is that possible? Thanks.

找到这样的回答: 为了svcutil.exe的不生成的客户端代理类型,你需要明确地引用wcfobjects.dll的提示:

Found this answer: in order for svcutil.exe to NOT generate the types in the client proxy, you need to explicitly reference the wcfobjects.dll at the prompt:

SvcUtil工具*的.wsdl *的.xsd /异步/ TCV:Version35 /语言:C#/r:\wcfobjects.dll /out:\Proxy.cs /config:\App.config

再次感谢。

推荐答案

在添加服务引用对话框中,在高级选项卡,指定重复使用现有的类型。

In the "Add Service Reference" dialog, on the "Advanced" tab, specify "Reuse existing types".