Overloading WebMethods

R

Raed Sawalha

I have webservice and I need to overload a method but when overloading the
method as following i got error message written below:

[WebMethod(Description="Gets the number of files in the User subfolder that
has that Type name")]
public int MessageCount (string User,string Type )
{
MsgWebService.Utility.UserFolder oUserFolder = new
MsgWebService.Utility.UserFolder(User);
string[] saFiles = oUserFolder.GetSubfolderFilesName(Type);
return (saFiles == null)? 0 : saFiles.Length ;
}

[WebMethod(Description="Gets the number of files in the User subfolder that
has that Type name")]
public int MessageCount (string User,string Type,string userId)
{
MsgWebService.Utility.UserFolder oUserFolder = new
MsgWebService.Utility.UserFolder(userId.Substring(0,4),userId);
string[] saFiles = oUserFolder.GetSubfolderFilesName(Type);
return (saFiles == null)? 0 : saFiles.Length ;
}


The Error :
*********
Both Int32 MessageCount(System.String, System.String, System.String) and
Int32 MessageCount(System.String, System.String) use the message name
'MessageCount'. Use the MessageName property of the WebMethod custom
attribute to specify unique message names for the methods.

Why I'm getting this error? I dont understand from the message what should I
do?
any help please?
 
E

erymuzuan

try to created a diffrent soapaction value for the operation. generally
the SoapAction will be used to bind to the appropriate method.

BTW, a better approach would be to use XML schema to determine the
correct parameter. don't get too fancy with web services as asp.net
might spit out a problematic wsdl and serilizer.

regards
erymuzuan
 
R

Raed Sawalha

Could you please provide me with more information
(try to created a diffrent soapaction value for the operation) ?


erymuzuan said:
try to created a diffrent soapaction value for the operation. generally
the SoapAction will be used to bind to the appropriate method.

BTW, a better approach would be to use XML schema to determine the
correct parameter. don't get too fancy with web services as asp.net
might spit out a problematic wsdl and serilizer.

regards
erymuzuan

Raed said:
I have webservice and I need to overload a method but when overloading the
method as following i got error message written below:

[WebMethod(Description="Gets the number of files in the User subfolder that
has that Type name")]
public int MessageCount (string User,string Type )
{
MsgWebService.Utility.UserFolder oUserFolder = new
MsgWebService.Utility.UserFolder(User);
string[] saFiles = oUserFolder.GetSubfolderFilesName(Type);
return (saFiles == null)? 0 : saFiles.Length ;
}

[WebMethod(Description="Gets the number of files in the User subfolder that
has that Type name")]
public int MessageCount (string User,string Type,string userId)
{
MsgWebService.Utility.UserFolder oUserFolder = new
MsgWebService.Utility.UserFolder(userId.Substring(0,4),userId);
string[] saFiles = oUserFolder.GetSubfolderFilesName(Type);
return (saFiles == null)? 0 : saFiles.Length ;
}


The Error :
*********
Both Int32 MessageCount(System.String, System.String, System.String) and
Int32 MessageCount(System.String, System.String) use the message name
'MessageCount'. Use the MessageName property of the WebMethod custom
attribute to specify unique message names for the methods.

Why I'm getting this error? I dont understand from the message what should I
do?
any help please?
 
A

Andy Babiec

A web service is like an http post, where the method name becomes the
unique part of the URL and the message (which in your case is the set
of parameters) is the contents being posted.

your web service will become...
POST /MyWebService.asmx/MessageCount

So you can't have two methods with the same name - thus no overloading.
Nothing to do with Visual Studio, .net, Microsoft.

Why don't you just publish MessageCount (string User,string Type,string
userId)
and let the user ignore the userId parameter - i.e. not pass it in.
 
B

Brock Allen

In essence Web Services is a different technology than C#. C# supports overloading
whereas WebServices don't. Just use a different name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top