Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

web service - optional parameter 1

Status
Not open for further replies.

JazzMaan

Programmer
Jun 15, 2004
57
US
I am writing a web service in c# that will have some required and some optional parameters.

How do I specify optional parameters ? so that the wsdl can show it as an optional ?
 
create overloaded public members
string Get(int i);
string Get(int i, string s);
string Get(int i, string s, DateTime d);

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
i have allready tried that.

i dont think overloading works in webservice. The wsdl dosent show 2nd or 3rd option.
 
I have tried
[WebMethod]

public void Get(int i){}
[WebMethod]
public void Get(int i, string s)
{}
[WebMethod]

It gives an error:
Both Void Get(Int32, System.String) and Void Get(Int32) use the message name 'Get'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Both Void Get(Int32, System.String) and Void Get(Int32) use the message name 'Get'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.
 
ok, then go this route
string GetByInt(int i);
string GetByIntAndString(int i, string s);
string GetByIntStringAndDate(int i, string s, DateTime d);

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
if that isn't an option, then pass default values to the service and handle accordingly.
string GetByIntStringAndDate(int i, string s, DateTime d);
using 0, "" and DateTime.Min values for the defaults.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top