I have a service method with a couple of parameters that will be always provided and additional parameters that will change by names and number of parameters (I will know which parameters to expect by the ACTION field)
To solve a design problem like the above I created a web service with the parameters that will be always provided and one more parameter that will accept a string that is written in a Key<*>value way.
using MyServiceMethod:
Action : Action1
Param2: Hello
param3: world
Additional_Params: name<*>Jack;address<*>2 street;
(I know that with Action1 I get a Name and address values from the person who uses the service)
using MyServiceMethod for the second time:
Action : Action5
Param2: Hello
param3: world
Additional_Params: numOfHours<*>3;Sum<*>342;myName<*>asaf;
I think this is not the best design for a web service that accept a different data with each ACTION, is there a better way to do that ?
I’ve kind of already answered in comments, but here it is in one place:
If you have a small number of different functions, which change rarely, the best way is just to expose each as a separate function. When new ones are needed, you can extend your interface without breaking existing code.
Now, on the other hand, if you had a larger number of functions and/or they changed frequently, then a simple but flexible interface would be better. You could have a single function exposed, taking an XML document that is a serialization of a request DTO. This will require some demux logic (switch/case or, better, a lookup table of delegates) to dispatch the requests to a handler. This approach is harder to get going, but easier to maintain.