Solved

Non mandatory parameters in a webservice??

Posted on 2004-08-25
3
706 Views
Last Modified: 2008-02-26
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
Comment
Question by:nicolajb
3 Comments
 
LVL 10

Expert Comment

by:123654789987
ID: 11890469
There is a particular XML tag called XMLIgnore.

You can try using it like this

[WebMethod]
public string Test(param1, XmlIgnore["param2"],param3)
{
}
0
 
LVL 19

Accepted Solution

by:
Desp earned 500 total points
ID: 11890482
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
 
LVL 9

Expert Comment

by:msdixon
ID: 11891680
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET HttpWebRequest 12 57
Different Delete Messages 7 37
Export import database 4 42
free scanner TWAIN can be operated with a Web application 9 39
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now