简体   繁体   中英

What is the best way of using WCF Service data structures

I'm creating a solution in C# using WCF Service. There is one project which has Service References set to My WCF Service, however I'll be using data structures from the server through multiple project. I'm wondering if it's better to using struct created in References to WCF Service or add reference to library which is created while Service is built?

It depends, as usual.

If your data structures are just that -- they hold data (properties) and do not contain any logic -- then it doesn't really matter. What the Service Reference proxy generator creates is basically the equivalent of the data types you have created in the service.

If you do want to have logic on those structures, and that logic applies to both the client and the server, it is best to put those classes in a shared library.

Of course this means that, when the service uses a newer version of that shared library, the client must do so too (although that would in reality depend on whether the changes you introduce are breaking, such as renaming or removing a property).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM