C# 带有可选参数的WebMethod不';不能在客户端工作

C# 带有可选参数的WebMethod不';不能在客户端工作,c#,c#-4.0,C#,C# 4.0,我编写了一个带有可选参数的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, b

我编写了一个带有可选参数的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
但是


我做错了什么?

在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)
{
     .....
}

Web方法应该独立于平台/语言,并且每种语言都不必支持可选参数。所以你的第一个版本是正确的。@I4V所以在web方法中使用可选参数没有任何意义。谢谢,但我知道重载方法,我想知道的是可选参数在web方法上不起作用,或者我做错了什么。不,它们就是不起作用。为什么我被否决了?有什么评论吗?解决方案错了吗?我想知道我是否犯了错误,谢谢。@DimitarDimitrov我错过了
MessageName
部分。如果你修改你的答案,我将投票。
[WebMethod]
public void EmailSend(MessageParameters messageParams)
{
     .....
}