c# - WebMethod with optional parameter doesn't work in client side -


i write webmethod optional parameter.

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

i call method in client side application

 emailservicemanagement.emailservice es = new emailservicemanagement.emailservice();  es.emailsend(from, to,null,null,null,subject,body,true,attname,att); //this works 

but

es.emailsend(from,to); // isn't working. according c# optional parameter syntax must work. 

what doing wrong?

you can't have optional parameters on webmethods. can have overloaded methods this:

[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); } 

not sure how you're interacting webmethod having many parameters indication can group them in object like:

[webmethod] public void emailsend(messageparameters messageparams) {      ..... } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -