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

Non mandatory parameters in a webservice??

Hi

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"?

/Nicolaj
0
nicolajb
Asked:
nicolajb
1 Solution
 
123654789987Commented:
There is a particular XML tag called XMLIgnore.

You can try using it like this

[WebMethod]
public string Test(param1, XmlIgnore["param2"],param3)
{
}
0
 
Fahad MukhtarDistinguished EngineerCommented:
C# lack this feature AFAIK.. even Vb.Net has this feature
http://oldlook.experts-exchange.com:8080/Programming/Programming_Languages/Dot_Net/Q_20829204.html

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)

OR
Here is another way to do that:
http://builder.com.com/5110-6373-1050802.html
using the same technique used by Console.WriteLine method, where u dont know how many parameters you will pass to this.
0
 
msdixonCommented:
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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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