Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable number of parameters to a web service method 2

Status
Not open for further replies.

CompCodeBoy

Programmer
Aug 18, 2005
33
US
I want to create web service. I need to call a method and pass any number of parameters. That is, call a method (function) and pass one argument, two arguments up to 200.
I tried to declare the parameters in the web service method as objects and call that method from a client application passing different number of arguments but that did not work. Any help would be appreciated. Thanks.
 
flat2,(works if not a web service method) I get the following error:
"No overload for method 'ShowErrors' takes '3' arguments." 'ShowErrors' is the web service method. What am I doing wrong?
 
It appears that you are trying to call a .NET library function called ShowErrors().

Since that function is built-in, you may not be able to overload it.

Try creating your own function called MyShowErrors() and pass that array in there like the URL states.

 
I changed the name and still does not work. I still get the same error. The example in the article worked if the method is not in a web service.
 
You cannot overload web methods. You have to create a new method for each parameter combination you need.
 
You actually can overload webmethods, however it is tricky. Here is how you do it:

First set the following line:

Code:
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.None)> _

It usually conforms to "Basic". Then create two methods with the same name. And give it an new "Message" name. For example

Code:
   <WebMethod(MessageName:="Send", Description:="Sends a basic email.  Body can be formatted for html.")> _
    Public Function Send()
'Your code here

   <WebMethod(MessageName:="SendWithAttachment", Description:="Sends a basic email.  Body can be formatted for html.")> _
    Public Function Send()
'Your code here

When you browse it will be two different methods using the "MessageName", however when you create a new instance reference in your code it will appear as an overloaded method. Might not be the best way, but it can be done.

Hope that helps,

J
 
Neither did I. Took quite a bit of googling... I thought this was pretty cool too.

As a side note, I kind of cut the code short on my example you'll need to put in a parameter in the second method, otherwise you'll get an identical method error (same if it wasn't an web method), and you'll need to add the return type and return type because it is a function (just wanted to add that in case someone was having problems with it.

This is slightly better :)

Code:
    <WebMethod(MessageName:="SendEmail", Description:="Sends a basic email.  Body can be formatted for html.")> _
   Public Function Send() As String
        'Your code here


    End Function

    <WebMethod(MessageName:="SendEmailWithAttachment", Description:="Sends an email with an attachment.")> _
     Public Function Send(ByVal param As String) As String
        'Your code here

    End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top