带可选参数的WebMethod不能在客户端工作
本文关键字:不能 客户端 工作 WebMethod 参数 | 更新日期: 2023-09-27 18:14:26
我写了一个带可选参数的webmethod
[WebMethod]
public void EmailSend(string from, string to, string cc = null, string bcc = null, string replyToList = null, string subject = null, string body = null, bool isBodyHtml = false , string[] attachmentNames = null, byte[][] attachmentContents = null)
{
.....
}
我在客户端应用程序
中调用这个方法 EmailServiceManagement.EmailService es = new EmailServiceManagement.EmailService();
es.EmailSend(from, to,null,null,null,subject,body,true,attName,att); //this works
,
es.EmailSend(from,to); // this isn't working. According to c# optional parameter syntax it must work.
我做错了什么?
WebMethods不能有可选参数。你能做的就是像这样重载方法:
[WebMethod(MessageName="Test")]
public string GenerateMessage(string firstName)
{
return string.Concat("Hi ", firstName);
}
[WebMethod(MessageName="AnotherTest")]
public string GenerateMessage(string firstName, string lastName)
{
return string.Format("Hi {0} {1}", firstName, lastName);
}
不确定你是如何与这个WebMethod交互的,但有这么多参数可能表明你可以将它们分组在一个对象中,比如:
[WebMethod]
public void EmailSend(MessageParameters messageParams)
{
.....
}