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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.