0

I have one [Operation Contract] where described function which registers a new user in WCF Service:

[OperationContract]
boolean Register(string name, string password);

This function accepts two parameters name and password of user. How I can extend these parameters in the future, for example If I want to add second name for register function or more parameters?

I can do the following:

boolean Register(string name, string password, string secondName);

But if params are more 20?

Ahmed
  • 255
  • 1
  • 6
  • 18

2 Answers2

2

If you don't mind breaking the contract for the operation that you want to change, you could combine some of the (more than 20) parameters into a class.

This is generally good practice when writing methods that have a lot of parameters (see also What's the best way to refactor a method that has too many (6+) parameters?).

You may probably need to add a [DataContract] attribute to that class then, though, if you want to use it in WCF calls.

Community
  • 1
  • 1
joranvar
  • 490
  • 5
  • 9
1

By using the params keyword, you can specify a method parameter that takes a variable number of arguments. like-

boolean Register(params string[] list);

Khairul Islam
  • 1,207
  • 1
  • 9
  • 20