Convert library to WCF web service

As the storyline describes, I am participating in the demonstration process of the C # library in the WCF service. In the end, we want to reveal all the functionality, but currently the area is limited to a subset of the library API. One of the goals of this exercise is also to ensure that the WCF service uses the Request / Response messaging template. Thus, the interface / API will change as the existing library does not use this template

I started by implementing Service Contracts and Request / Response objects, but when it comes to developing DataContracts, I'm not sure where to go. I am divided between returning and annotating existing library classes with DataContract / DataMember VS attributes defining new classes that are surrogate classes for existing classes.

Does anyone have experience with a similar task or any recommendations on which method works best? I would like to point out that our team owns an existing library, so it has the source code for it. Any pointers or recommendations would be helpful.

+4
source share
3 answers

My recommendation is to use an adapter template, which in this case basically means creating new DataContracts and ServiceContracts. This will dispense with each other and allow you to optimize WCF material for WCF and API for API (if that makes sense). The last thing you want is to go along the modification route and find that something just will not display correctly once you are almost done.

+4
source

Starting with .NET 3.5 SP1, you no longer need to decorate the objects you want to open with the [DataContract] / [DataMember] . All open properties will automatically open. At the same time, I personally prefer to use special DTO objects, which I open and decorate with these attributes. Then I use AutoMapper to map between the actual domain models and the objects I want to open.

+2
source

If you intend to continue to use the existing library, but want to have control over what you show as the web service API, I would recommend defining the new classes as wrappers (s) around the library.

What I want to say is not to โ€œtransformโ€ the existing library, even if you think you are not going to use it in other contexts. If it has been tested and verified, take advantage of this fact and wrap it.

+1
source

All Articles