简体   繁体   English

具有可选参数的C#Web服务方法

[英]C# Web Service Method with Optional Parameters

I want to build a WebMethod with Optional Parameters. 我想用可选参数构建一个WebMethod

I knew the way to set MessageName . 我知道设置MessageName的方法。

[WebMethod(MessageName = "Default")]
public void SearchPerson(String finger_print_base64)
{

}

[WebMethod(MessageName = "AddThreshold")]
public void SearchPerson(String finger_print_base64,int threshold)
{

}

But I want to set two parameters with same type. 但是我想用相同的类型设置两个参数。

[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)
{

}

And the Visual Studio told me an error. 而且Visual Studio告诉我一个错误。

"SearchPerson already hava an method with the same type of parameters " “ SearchPerson已经具有一种具有相同类型参数的方法”

You have tow methods with same signature , at least change the data type of one parameter or add another parameter like (boolean one) ! 您必须具有两个具有相同签名的方法,至少要更改一个参数的数据类型或添加另一个参数(布尔值)!

changing the name of parameter is not a solution. 更改参数名称不是解决方案。

At first : Overload in web-methods is not supported , IIS can't handle it. 首先:不支持Web方法中的重载,IIS无法处理它。

Now The compiler can't build tow or more methods with the same name and signature under the same class , Because of , how it can address the method in the "dll" file without confuse! 现在,由于相同的原因,编译器无法在相同的类下构建两个或多个具有相同名称和签名的方法,因此,如何在不混淆的情况下解决“ dll”文件中的方法! ,, ,,

if you want to call your methods use Interface or abstract class and override the method from it in new three classes and call them :) 如果要调用方法,请使用Interface或抽象类,并在新的三个类中重写该方法,然后调用它们:)

"MessageName" is just an Allies “ MessageName”只是一个盟友

No Overload Because of the method name became an (address, or Url , etc) so the application will route to is without caring for it's signature , programming feature or even it's Programming language. 无重载由于方法名称变成了(地址或Url等),因此应用程序将路由到该方法而无需关心其签名,编程功能甚至是编程语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM