• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 736
  • Last Modified:

Non mandatory parameters in a webservice??


I'm about to make a webservice to handle logins from a windows pplication.
I need to make a method that takes userid/password and another method that takes userid/password/attribute1/attribute2.

I thought about just making one webmethod that took the 4 parameters as input. The problem is that the application uses http GET when contacting the webservice and when using GET the webmethod fails if some parameters are missing??

Is it possible to make some of the parameters "non mandatory"?

1 Solution
There is a particular XML tag called XMLIgnore.

You can try using it like this

public string Test(param1, XmlIgnore["param2"],param3)
Fahad MukhtarDistinguished EngineerCommented:
C# lack this feature AFAIK.. even Vb.Net has this feature

you can use overloading functions(polymorphism) ...but using some tricks you can acheive that as well:

using System.Reflection;
public bool GenerateRequest(string ,string ,string ,long ,string ,string ) // normal case

//you can use  System.Reflection.Missing.Value to pass optional parameters which are missed. so you call your GenerateRequest Method like this:

public bool GenerateRequest(string ,string ,string ,long ,  Missing.Value,  Missing.Value)

Here is another way to do that:
using the same technique used by Console.WriteLine method, where u dont know how many parameters you will pass to this.
one way i've handled this is to pass in an xml string (or XmlDocument if you prefer). this allows great flexibility, and parsing xml is pretty easy.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now