Solved

Non mandatory parameters in a webservice??

Posted on 2004-08-25
3
705 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contant UI messages in .NET 1 41
network + 7 73
import issue in bit values 3 44
C# Application Local DB Connection String 23 61
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

12 Experts available now in Live!

Get 1:1 Help Now