想要使用C#的asmx的WebMethod来实现一个WebService,。
想要用户给服务器传递数据,finger_print_base64
是一个必须传递的固定参数,threshold
和 mini_matches
是两个可选参数。
目前已知可以定义MessageName 来通过方法重载实现相同方法名的可选参数
[WebMethod(MessageName = "Default")]
public void SearchPerson(String finger_print_base64)
{
}
[WebMethod(MessageName = "AddThreshold")]
public void SearchPerson(String finger_print_base64,int threshold)
{
}
[WebMethod(MessageName = "AddMinMatches")]
public void SearchPerson(String finger_print_base64,int mini_matches)
{
}
但是,由于第二个方法和第三个方法的参数类型是相同的,无法实现重载。
想知道是否有其他方法来实现可选参数。
因为这是一个功能的接口,不想要改变方法名:SearchPerson
,所以不想通用不同的方法名来进行区分。
提前谢过各位大佬。
加参就是了。反正你可用可不用,加一个可选参数就是了
[WebMethod(MessageName = "AddThreshold")]
public void SearchPerson(String finger_print_base64,int threshold = 0,string param = "")
{
}
[WebMethod(MessageName = "AddMinMatches")]
public void SearchPerson(String finger_print_base64,int mini_matches = 0)
{
}