Larry Brister
asked on
C# WebMethod Nullable
How do I make a C# web method optional?
[WebMethod]
public string tabApiADSetLead(string user, string token, string location)
... etc
string loctaion to be optional
[WebMethod]
public string tabApiADSetLead(string user, string token, string location)
... etc
string loctaion to be optional
ASKER
ste5an
You are usually helpful... and maybe you don;t see the tone in your question?
OK... In a C# WebMwthod I need a paramater to be an optional one
I "think" this should work?
add... using System.Runtime.InteropServices;
change to string location to this?
[Optional, DefaultParameterValue(null)] string Location
You are usually helpful... and maybe you don;t see the tone in your question?
OK... In a C# WebMwthod I need a paramater to be an optional one
I "think" this should work?
add... using System.Runtime.InteropServices;
change to string location to this?
[Optional, DefaultParameterValue(null)] string Location
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
In C# you can declare several versions of a method:
// 1
public string tabApiADSetLead(string user, string token, string location){
...
}
// 2
public string tabApiADSetLead(string user, string token) {
tabApiADSetLead(user, token, ""); // it calls previous function with the location = ""
}
If you use tabApiADSetLead(user, token, location) it executes (1).
If you use tabApiADSetLead(user, token) it executes (2). In (2) you can replace "" with any default value.
It has the name "Method overloading". Read details here: https://www.geeksforgeeks.org/c-sharp-method-overloading/
// 1
public string tabApiADSetLead(string user, string token, string location){
...
}
// 2
public string tabApiADSetLead(string user, string token) {
tabApiADSetLead(user, token, ""); // it calls previous function with the location = ""
}
If you use tabApiADSetLead(user, token, location) it executes (1).
If you use tabApiADSetLead(user, token) it executes (2). In (2) you can replace "" with any default value.
It has the name "Method overloading". Read details here: https://www.geeksforgeeks.org/c-sharp-method-overloading/
@Andrei, afaik this requires to map each overloaded mtehod to a separate web mtehod in the controller´ as web services don't allow overloading.
Maybe you should consider rephrasing your question and providing more context.