J
john bailo
Can a web method be overloaded?
To support varying numbers of input parameters?
To support varying numbers of input parameters?
Greg Ewing said: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 said:Can a web method be overloaded?
To support varying numbers of input parameters?
john bailo said: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 said: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 said:Can a web method be overloaded?
To support varying numbers of input parameters?
john, the client will have to use Add2.
Hi,
No Web Service methods can not be overloaded. If you want to expose an
You can easily handle this by making the web method accept a XMLDocumentBurgess said:Chris Taylor dribbled:
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.
Chris Taylor said: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 said:Can a web method be overloaded?
To support varying numbers of input parameters?
Bubba Thomas said: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 said: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 said:Can a web method be overloaded?
To support varying numbers of input parameters?