Creating separate “model” classes from a WCF service

I would like to be able to generate separate classes (one class for each file) for each Data Contract or XML type in the WCF web service.

I read the svcutil documentation, and if I didn't work too fast, it doesn't seem like the tool supports this behavior.

The reason I want to do this is simple - I'm trying to isolate the service “model” from the service itself. There are several components that rely on types from a service, but do not care about the details of service level operations, such as loading / saving. I do not like the fact that these components should take dependencies on the same assembly, which contains all kinds of call logic and bindings.

I know that svcutil (and VS integration) can be configured to use pre-existing model classes in another assembly. This is a chicken and egg problem; I really don't want to write 50 classes manually, which (at least for now) are almost identical to the generated classes. And of course, I have to add all the DataContract attributes with namespaces and other WCF attributes ... this is a pain.

My ultimate goal is to actually have a view / domain model that is completely independent of the service model, but I don't have cycles yet. I think that creating an artificial model, which can ultimately be formed into a true representation model, will be a good, quick and easy way to begin this journey. After that, I can set up service links to use separately created proxy classes and start generating something more reliable.

Can this be done? Are there options for svcutil that will cause it to generate one class for each file? Or is there another tool that can do this?

+4
source share
1 answer

I do not know a single tool that would support this at this time - I would like to learn about such a tool myself if it exists!

If you have cycles to attack this on your own, you could

  • take the WSDL service from the URL (or load it from a file)
  • parse XML classes defined in an embedded XML schema
  • use something like T4 templates or another mechanism to generate C # code from these XML schemas.

This is definitely possible - and maybe not even really all that complicated - but who has the time to do this ?:-)

0
source

Source: https://habr.com/ru/post/1302889/


All Articles