开发者

Class names generated using Svcutil giving a problem

I'm trying to generate a proxy in the Presentation layer from the Business Layer service..

My problem is I've two classes with the same name being exposed, though in different namespaces.

say, Business.AddressInfo and Data.AddressInfo

The proxy generated changes the AddressInfo in Business to AddressInfo1.

How do I contro开发者_StackOverflow中文版l it?


This is standard WCF behavior and cannot be "controlled" - that's the way it works.

When the WCF runtime / svcutil does the "Add Service Reference", it reads the service documents (WSDL, XSD) and from those descriptions, it builds the client-side proxy - both the service proxy (with the methods calling the service) and the client-side data representations.

The only thing a WCF client and service share is the representation of the data on the wire - e.g. the client-side proxy data classes will serialize into the same XML format as the server-side classes do. After all: WCF is a message-passing system - there's no connection other than the serialized messages between the client and the server.

Those client-side proxy classes get generated into a namespace of your choosing - you can control this, but they'll always be separate classes in a separate namespace.

There are basically two ways to deal with this:

  1. you can use something like AutoMapper to map between those classes, where needed; since the serialization format on the wire is the same, so are the property names, and thus mapping from one object type to the other should be very straightforward and simple

  2. if you control both ends of the wire, e.g. both the server and the client, and both are on .NET, you can also put all your service contracts, data contracts and so forth into a separate class library assembly, and then share that assembly between server and client. That way, when you do "Add Service Reference", the WCF runtime will re-use the existing types in the shared assembly that is referenced, and it will not create client-side proxy classes again. With this "trick", both your server and your client will be using the identical classes from that common, shared assembly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜