I have a ASP.NET MVC application that needs to communicate with a third-party using a web service. The service is simple enough. It provides a single method that takes an XML request and provides an XML response.
There are various different types of XML request messages that can be sent and they always have a matching corresponding response format. These can be thought of as a series of request/response pairs. The only time the returned XML response differs in format for a particular type of request is when an error has occured at the third-party's side of things (e.g. bad data was passed).
When a MVC view is posted the controller code will call a service layer method e.g. ProcessStep1(model). This method (or something this method calls) will need to examine data within the passed-in model and determine what kind of request/response pair to build.
Similarly, upon receiving an XML response specific code for that response type will need to be executed to re-populate a model (before eventually being passed up to my MVC view). The response is paired with that particular request type but if errors have occured different code will need to run.
I am familiar with some of the concepts of design patterns but have limited experience of using them in real-world scenarios. I'm sure they could be put to use here to help keep the code organisied and clean.
Can anyone suggest a structure to acheive my goal? Which patterns would be useful here and what would be a clean-way of solving this problem (builder, factory, mediator)? Please, all suggestions are welcome.
Aucun commentaire:
Enregistrer un commentaire