473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Webservice with optional parameters

I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.

I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....

thanks

Sam

May 9 '07 #1
7 13446
On May 9, 4:56 pm, Sam Shrefler <sshref...@gmail.comwrote:
I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.

I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....
Make it take a single parameter of a type which encapsulates the
record. For optional reference type fields, use null to avoid
specifying the value. For optional value type fields, either have a
separate flag or have a "magic" value which means "no real
value" (e.g. int.MinValue for integers).

Jon

May 9 '07 #2
Is there any way to use Nullable<intor Nullable<dateTimein the in
the record?

Thanks

Sam
On May 9, 11:59 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On May 9, 4:56 pm, Sam Shrefler <sshref...@gmail.comwrote:
I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.
I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....

Make it take a single parameter of a type which encapsulates the
record. For optional reference type fields, use null to avoid
specifying the value. For optional value type fields, either have a
separate flag or have a "magic" value which means "no real
value" (e.g. int.MinValue for integers).

Jon

May 9 '07 #3
I think what Jon is saying is you should consider having your method accept
an object of type Record as the single parameter to your WebMethod.
Inside the body of the method, you can then easily access the values of the
10 fields that you actually need, and just forget about the others.
Keep it simple!
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Sam Shrefler" wrote:
Is there any way to use Nullable<intor Nullable<dateTimein the in
the record?

Thanks

Sam
On May 9, 11:59 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On May 9, 4:56 pm, Sam Shrefler <sshref...@gmail.comwrote:
I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.
I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....
Make it take a single parameter of a type which encapsulates the
record. For optional reference type fields, use null to avoid
specifying the value. For optional value type fields, either have a
separate flag or have a "magic" value which means "no real
value" (e.g. int.MinValue for integers).

Jon


May 9 '07 #4
I'm sorry,I guess I didn't explain myself very well there.

I have a webMethod called saveUser

It must receive user information. Some of the information needs to be
optional. Some is required (represented with a *):

string firstName*
string middleName
string lastName*
dateTime birthday*
dateTime anniversary
dateTime death
int userTypeID

I need my method able to accept all of them, yet, it can't force them
to send an anniversaryDate time...

Any suggestions on something like that?

Thanks

Sam
On May 9, 1:41 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
I think what Jon is saying is you should consider having your method accept
an object of type Record as the single parameter to your WebMethod.
Inside the body of the method, you can then easily access the values of the
10 fields that you actually need, and just forget about the others.
Keep it simple!
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Sam Shrefler" wrote:
Is there any way to use Nullable<intor Nullable<dateTimein the in
the record?
Thanks
Sam
On May 9, 11:59 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On May 9, 4:56 pm, Sam Shrefler <sshref...@gmail.comwrote:
I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.
I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....
Make it take a single parameter of a type which encapsulates the
record. For optional reference type fields, use null to avoid
specifying the value. For optional value type fields, either have a
separate flag or have a "magic" value which means "no real
value" (e.g. int.MinValue for integers).
Jon- Hide quoted text -

- Show quoted text -

May 9 '07 #5
Well, if that's the way you must do it, then why not just leave the optional
parameters "blank" - either an empty string ( "") or null, whichever fits
your types, when the values are passed into your method?

For a DateTime, you can pass DateTime.MinValue (which is not a "null") and
just check for that.

So, you can check to see if optional parameters have a value, and decide
what to do.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Sam Shrefler" wrote:
I'm sorry,I guess I didn't explain myself very well there.

I have a webMethod called saveUser

It must receive user information. Some of the information needs to be
optional. Some is required (represented with a *):

string firstName*
string middleName
string lastName*
dateTime birthday*
dateTime anniversary
dateTime death
int userTypeID

I need my method able to accept all of them, yet, it can't force them
to send an anniversaryDate time...

Any suggestions on something like that?

Thanks

Sam
On May 9, 1:41 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
I think what Jon is saying is you should consider having your method accept
an object of type Record as the single parameter to your WebMethod.
Inside the body of the method, you can then easily access the values of the
10 fields that you actually need, and just forget about the others.
Keep it simple!
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Sam Shrefler" wrote:
Is there any way to use Nullable<intor Nullable<dateTimein the in
the record?
Thanks
Sam
On May 9, 11:59 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On May 9, 4:56 pm, Sam Shrefler <sshref...@gmail.comwrote:
I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.
I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....
Make it take a single parameter of a type which encapsulates the
record. For optional reference type fields, use null to avoid
specifying the value. For optional value type fields, either have a
separate flag or have a "magic" value which means "no real
value" (e.g. int.MinValue for integers).
Jon- Hide quoted text -
- Show quoted text -


May 9 '07 #6
I'd rather not use minValue since this webservice will be consumed by
many different platforms. Instead what i am trying to do is declare
my params as DateTime? and int?

That way, hopefully the user can just send an empty param <myDateTime/
and that will be received as null.
I'm creating and waiting for some tests to occur.

Does this seem like a viable solution?

On May 9, 3:00 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Well, if that's the way you must do it, then why not just leave the optional
parameters "blank" - either an empty string ( "") or null, whichever fits
your types, when the values are passed into your method?

For a DateTime, you can pass DateTime.MinValue (which is not a "null") and
just check for that.

So, you can check to see if optional parameters have a value, and decide
what to do.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Sam Shrefler" wrote:
I'm sorry,I guess I didn't explain myself very well there.
I have a webMethod called saveUser
It must receive user information. Some of the information needs to be
optional. Some is required (represented with a *):
string firstName*
string middleName
string lastName*
dateTime birthday*
dateTime anniversary
dateTime death
int userTypeID
I need my method able to accept all of them, yet, it can't force them
to send an anniversaryDate time...
Any suggestions on something like that?
Thanks
Sam
On May 9, 1:41 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
I think what Jon is saying is you should consider having your method accept
an object of type Record as the single parameter to your WebMethod.
Inside the body of the method, you can then easily access the values of the
10 fields that you actually need, and just forget about the others.
Keep it simple!
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Sam Shrefler" wrote:
Is there any way to use Nullable<intor Nullable<dateTimein the in
the record?
Thanks
Sam
On May 9, 11:59 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On May 9, 4:56 pm, Sam Shrefler <sshref...@gmail.comwrote:
I'm working on creating a WebService / WebMethod to receive a record
in real time from another system. The record contains about 20
fields. 10 of which aren't required.
I was planning on just making a method with 20 parameters. But, I see
there is no way to make an "optional" c# parameter. I was just
wondering if anyone had an suggestions on how to implement this? The
parameters are all different primitive types (int, string,
datetime)....
Make it take a single parameter of a type which encapsulates the
record. For optional reference type fields, use null to avoid
specifying the value. For optional value type fields, either have a
separate flag or have a "magic" value which means "no real
value" (e.g. int.MinValue for integers).
Jon- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 9 '07 #7
Sam Shrefler <ss*******@gmail.comwrote:
I'd rather not use minValue since this webservice will be consumed by
many different platforms. Instead what i am trying to do is declare
my params as DateTime? and int?
Using int.MinValue is a *lot* more portable than using nullable types.
How would you expect Record to be represented on a platform which
doesn't have nullable types?

Compare that with using int.MinValue, which will always be the minimum
value of a 32-bit 2's complement integer.

Using DateTime.MinValue is a bit riskier - you'd have to have a well-
defined date/time which is representable on all target platforms, and
use that everywhere.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 9 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
2
by: Detroit | last post by:
all, while converting a .net class file to a xml webservice i have encountered some problems. First I cannot seem to be able to pass optional parameters to a web method. I have also found problems...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
1
by: peridian | last post by:
This is more of a general question, but I didn't know where to post it. Since Java is an example of a language which does this, I thought here would work. Coming from a C++ background, having...
0
by: lehu | last post by:
Hi, I have created web service, it's practically finished, but I wanted to do some improvements in generated wsdl: - For string parameters i get element tag such as this in wsdl: <s:element...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.