c# - Use auto-generated classes/objects when using a SOAP WS in .NET? -


at current project have develop .net client application uses handful of soap web services communicate external software.

fortunately .net makes easy use soap ws generates required objects when adding service reference.

on other hand after playing around auto generated classes while i'm not sure if it's better use them directly in business logic or if should map them own models (e.g. using repository pattern).

pros mapping:
- separation of business logic , data access (ws change)
- central point calls ws (can validate responses , proper error handling)
- ws types cumbersome use (e.g. webservice1.typea not compatible webservice2.typea).
- generated classes cannot/should not customized.
- ...

cons mapping:
of used wsdls have complex structure , lots of nested types. in case of mapping them own models have duplicate many classes , properties. that's fact why have concerns solution.

in short i'm unsure if duplication of web service classes own namespaces , implementation of repository or facade pattern proper way go or blowing architecture.

are there best practices or similar?

in 20+ years of experience, adding repository/service layer can overkill if lifetime of project uncertain or short lived. there added concern of performance, soap more of bottleneck object mapping layer when done correctly. also, naked object applications don’t benefit separation of concerns.

that being said, if connecting soap endpoint these days developing enterprise application should built around few years , enhanced on time. is, built accept growing needs. far pros , cons, in experience depends on return on time investment. information posted here, effort beneficial.

generation can great tool when done right. considerable amount of t4 generation in projects similar purposes. far best practices, generate classes ‘generated’ sub namespace , extend them. way can extend functionality , structure without fear of them being overwritten. in generated classes mark partial , virtual have options outside of inheritance. may overkill @ once, consider. leveraging partial classes way modify , extend generated classes.
can generate extended/partial classes. use t4toolbox generate external files , use ‘preserveexistingfile’ prevent file being overwritten. t4toolbox (if aren’t using it) offers great modular way manage generation, generate other projects.

even if don’t add repository layer, encourage apply concepts of composite , façade patterns simplify interaction external service.

so in review, best practices in experience:

repository:

  • if need long-lived , extendable

generation:

  • use namespace , class naming makes clear class generated , overwritten.
  • create classes partials or extend generated classes flexibility

t4toolbox if using t4

  • modular t4
  • preserve custom code

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -