Passing a Null to Web Method

J

J. L. Goddard

1) Do c# web methods support default parameters ?


2) Can a web method, or a c# method such as:

public nullTest( int i )
{
return i++;
}

Can the web service consumer pass in a value of nullTest(null) ?


3) What if the web service is passing in a series of records where some
of the data for that parameter is null ? How should a null be passed
to the web service ?
 
N

novelle.vague

Razzie wrote:

Thanks. That's a good blog.

Unfortunately for us web methods don't support overloading !

So for a consumer of a web service, he has to account for all parameters
with 'dummy data' I guess...

That means if his value is null, for an int, and he wants to pass a record
to me with a web service/method, he has to make up a value like 0, and use
that.

That's not good integrity.
 
W

William Stacey [MVP]

Not sure I understand the question fully. But you could box the int in an
object and pass that or null ( I think ) or create a DBInt struct value type
like in Anders H. C# book (I just saw the code a bit.)
 
N

novelle.vague

William said:
Not sure I understand the question fully. But you could box the int in an
object and pass that or null ( I think ) or create a DBInt struct value
type like in Anders H. C# book (I just saw the code a bit.)

So are you saying given:

public int NullTest(int i)
{
returns i++;
}

I could say:


object o = null; // box null into an object box
int value2 = (int) o; // unbox into value2
public int NullTest(value2); // ???

Or should I configure NullTest() like:

public int NullTest(obj o)
{
returns ((int) o) ++ ;
}

And call it with

object o = null;
int j = NullTest(o); // ???

Because a datatype o can be null, but a datatype int cannot accept a null
value when passed in as a parameter ?
 
J

Jeff Relf

Hi novelle.vague ( Maestro Bailo ),

You asked if nullTest() could call this:

nullTest( int i ) { return i ++ ; }

If it's like C++, the answer is no.

nullTest() with no parameters would give a compile-time error.

But, if " i " is a global, for example,
you could overload nullTest() like this:

nullTest() { return i ++ ; }

nullTest( int J ) { return i = ++ J ; }

Re: Your: nullTest( null ),

NULL is a macro in C++, it's defined as 0 ( Zero ).

Did you mean: nullTest( void ) ?

You asked: <<
3) What if the web service is passing in
a series of records where some
of the data for that parameter is null ?

How should a null be passed to the web service ? >>

Create overloaded functions ?

Re: http://kentpsychedelic.blogspot.com ,

Your blog really rocks. You're a genius Bailo.

But my FireFox .9 was caching it...
I wasn't seeing the latest version.
( I think I've fixed that now )

Did you have a stroke ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top