Solved

Non mandatory parameters in a webservice??

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Object Oriented Programming, C#, referencing, scoping. 13 86
Upgrade code from VS 2010 to VS 2015 7 33
Visual Studio 2015 auto inserted code 12 70
aspx ascx, c# 7 17
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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