PC Review


Reply
Thread Tools Rate Thread

Can web methods be overloaded ?

 
 
john bailo
Guest
Posts: n/a
 
      15th Oct 2003

Can a web method be overloaded?

To support varying numbers of input parameters?



 
Reply With Quote
 
 
 
 
Greg Ewing [MVP]
Guest
Posts: n/a
 
      15th Oct 2003
john, yes you can but you need to specify the MessageName attribute though
as an alias for the WSDL. Here's an example.

<%@ WebService Language="C#" Class="Calculator" %>

using System;
using System.Web.Services;

public class Calculator : WebService {
// The MessageName property defaults to Add for this XML Web service
method.
[WebMethod]
public int Add(int i, int j) {
return i + j;
}
[WebMethod(MessageName="Add2")]
public int Add(int i, int j, int k) {
return i + j + k;
}
}

--
Greg Ewing [MVP]
http://www.citidc.com


"john bailo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Can a web method be overloaded?
>
> To support varying numbers of input parameters?
>
>
>



 
Reply With Quote
 
john bailo
Guest
Posts: n/a
 
      15th Oct 2003
if I want to use 3 parameters,

when I call the method from a client,

do I use Add or Add2 as my method?

Or is an 'alias' just a 'cosmetic' name for the overloaded
Add function?

"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote in message
news:%(E-Mail Removed)...
> john, yes you can but you need to specify the MessageName attribute though
> as an alias for the WSDL. Here's an example.
>
> <%@ WebService Language="C#" Class="Calculator" %>
>
> using System;
> using System.Web.Services;
>
> public class Calculator : WebService {
> // The MessageName property defaults to Add for this XML Web service
> method.
> [WebMethod]
> public int Add(int i, int j) {
> return i + j;
> }
> [WebMethod(MessageName="Add2")]
> public int Add(int i, int j, int k) {
> return i + j + k;
> }
> }
>
> --
> Greg Ewing [MVP]
> http://www.citidc.com
>
>
> "john bailo" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > Can a web method be overloaded?
> >
> > To support varying numbers of input parameters?
> >
> >
> >

>
>



 
Reply With Quote
 
Greg Ewing [MVP]
Guest
Posts: n/a
 
      15th Oct 2003
john, the client will have to use Add2.

--
Greg Ewing [MVP]
http://www.citidc.com

"john bailo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> if I want to use 3 parameters,
>
> when I call the method from a client,
>
> do I use Add or Add2 as my method?
>
> Or is an 'alias' just a 'cosmetic' name for the overloaded
> Add function?
>
> "Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote in message
> news:%(E-Mail Removed)...
> > john, yes you can but you need to specify the MessageName attribute

though
> > as an alias for the WSDL. Here's an example.
> >
> > <%@ WebService Language="C#" Class="Calculator" %>
> >
> > using System;
> > using System.Web.Services;
> >
> > public class Calculator : WebService {
> > // The MessageName property defaults to Add for this XML Web service
> > method.
> > [WebMethod]
> > public int Add(int i, int j) {
> > return i + j;
> > }
> > [WebMethod(MessageName="Add2")]
> > public int Add(int i, int j, int k) {
> > return i + j + k;
> > }
> > }
> >
> > --
> > Greg Ewing [MVP]
> > http://www.citidc.com
> >
> >
> > "john bailo" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > Can a web method be overloaded?
> > >
> > > To support varying numbers of input parameters?
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Chris Taylor
Guest
Posts: n/a
 
      15th Oct 2003
Hi,

No Web Service methods can not be overloaded. If you want to expose an
overloaded class method, you will have to provide a alias using the
MessageName property of the WebMethodAttribute.

C# : [WebMethod( MessageName="GetCustomerByID" )]

VB.NET <WebMethod( MessageName := "GetCustomerByID)>

Hope this helps

Chris Taylor

"john bailo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Can a web method be overloaded?
>
> To support varying numbers of input parameters?
>
>
>



 
Reply With Quote
 
Burgess Meredith
Guest
Posts: n/a
 
      15th Oct 2003
Greg Ewing [MVP] dribbled:

> john, the client will have to use Add2.


Is that 'overloaded' then?

Isn't that just the same as two methods?



 
Reply With Quote
 
Burgess Meredith
Guest
Posts: n/a
 
      15th Oct 2003
Chris Taylor dribbled:

> Hi,
>
> No Web Service methods can not be overloaded. If you want to expose an


ok, so the benefits of overloading
are lost when calling a web method.

to me, that's a shame, because the ability
to send varying numbers of parameters and
parameter types to the same method would be
really valuable for a remote client, talking
to a web method.

if you think http post, there may be several
uses of the same function but with different
UI's that would want to use the method.


 
Reply With Quote
 
Greg Ewing [MVP]
Guest
Posts: n/a
 
      15th Oct 2003
Burgess, in terms of the server code, yes, it's overloading. In terms of
the client, no, it's not. Unfortunately that's a limitation of WSDL.

http://www.w3.org/TR/wsdl

--
Greg Ewing [MVP]
http://www.citidc.com


"Burgess Meredith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Greg Ewing [MVP] dribbled:
>
> > john, the client will have to use Add2.

>
> Is that 'overloaded' then?
>
> Isn't that just the same as two methods?
>
>
>



 
Reply With Quote
 
Girish Bharadwaj
Guest
Posts: n/a
 
      15th Oct 2003
Burgess Meredith wrote:

> Chris Taylor dribbled:
>
>
>>Hi,
>>
>>No Web Service methods can not be overloaded. If you want to expose an

>
>
> ok, so the benefits of overloading
> are lost when calling a web method.
>
> to me, that's a shame, because the ability
> to send varying numbers of parameters and
> parameter types to the same method would be
> really valuable for a remote client, talking
> to a web method.
>
> if you think http post, there may be several
> uses of the same function but with different
> UI's that would want to use the method.
>
>

You can easily handle this by making the web method accept a XMLDocument
as input rather than explicit parameters. They you would have control
over the kind of stuff you can get into that web method and you would
need to overload methods.

Of course, this would mean that you now have to write code to
de-serialize XML document to a real object. But that is a *good* thing.


--
Girish Bharadwaj

 
Reply With Quote
 
Bubba Thomas
Guest
Posts: n/a
 
      25th Nov 2003
Chris,

I tried your VB.NET version but it does not work. Firstly, I think you
forgot the closing " after GetCustomerByID but I get the following error !


Attribute "WebMethodAttribute" cannot be applied to '.ctor' because the
attribute is not valid on this attribute type.


Any ideas ?


ThanX !

Bubba !



"Chris Taylor" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> No Web Service methods can not be overloaded. If you want to expose an
> overloaded class method, you will have to provide a alias using the
> MessageName property of the WebMethodAttribute.
>
> C# : [WebMethod( MessageName="GetCustomerByID" )]
>
> VB.NET <WebMethod( MessageName := "GetCustomerByID)>
>
> Hope this helps
>
> Chris Taylor
>
> "john bailo" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > Can a web method be overloaded?
> >
> > To support varying numbers of input parameters?
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delegates for overloaded methods? Brian Hampson Microsoft C# .NET 8 9th Sep 2006 12:28 AM
XML Documentation in .NET 2.0 and <see...> links to overloaded methods =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= Microsoft C# .NET 1 2nd Dec 2005 09:16 AM
Overloaded methods =?Utf-8?B?cG1jZ3VpcmU=?= Microsoft VB .NET 4 19th May 2005 03:07 PM
Can web methods be overloaded ? john bailo Microsoft C# .NET 10 27th Nov 2003 12:17 AM
Accessing C# Overloaded methods from VB6 Arijit Chakraborti Microsoft Dot NET Framework 2 18th Sep 2003 10:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:40 PM.