7 Replies - 3913 Views - Last Post: 17 June 2009 - 05:08 AM Rate Topic: -----

#1 reCoded  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 282
  • Joined: 25-February 08

Web method overloading

Posted 16 June 2009 - 11:08 AM

I have the following two web methods in the same web service.

		[WebMethod(MessageName = "Get data by name and part number")]
		[SoapHeader( "WorkEnvironment" )]
		public List<Scratch> GetOpenStatements( string name, string partNumber)
		{



and

		[WebMethod(MessageName = "Get data by last name and part number")]
		[SoapHeader( "WorkEnvironment" )]
		public List<Scratch> GetOpenStatements( string lastName, string partNumber)
		{



I was thinking that is how I could over load the method but for some reason it is not working. Any one have any ideas? Am I overloading these methods correctly?

Thanks,
reCoded

Is This A Good Question/Topic? 0
  • +

Replies To: Web method overloading

#2 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: Web method overloading

Posted 16 June 2009 - 11:22 AM

It looks like both of your GetOpenStatements have the same signature
1
GetOpenStatements (string,string)
2
GetOpenStatements (string,string)


Here is an example of what your looking for.
http://www.codeproje...L/RefAndOL.aspx
Was This Post Helpful? 1

#3 Diomedes  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 23
  • Joined: 16-June 09

Re: Web method overloading

Posted 16 June 2009 - 11:24 AM

I think the issue is that both methods are currently identical from the perspective of the program. They both have the same name, visibility, return type, and arguments. Unless I missed something you just renamed the first string to be "lastName" but it's still a string.

Hence if you think about how you invoke an overloaded method, it looks for a method that would match the name and arguments, but in your case there would be two.
Was This Post Helpful? 0
  • +
  • -

#4 reCoded  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 282
  • Joined: 25-February 08

Re: Web method overloading

Posted 16 June 2009 - 12:08 PM

Thanks. Also it didn't mention that

[WebServiceBinding( ConformsTo = WsiProfiles.None )]

WsiProfiles should be set to None.
Was This Post Helpful? 0
  • +
  • -

#5 JayFCox  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 41
  • Joined: 31-May 09

Re: Web method overloading

Posted 16 June 2009 - 05:28 PM

the following quote has been altered

View PostreCoded, on 16 Jun, 2009 - 10:08 AM, said:

I have the following two web methods in the same web service.

		<snip/>
		public List<Scratch> GetOpenStatements( string name, string partNumber)
		{



and

		<snip/>
		public List<Scratch> GetOpenStatements( string lastName, string partNumber)
		{



<snip/>

Uh????!?!?
Ignore the Web Method anotations.... how is essentially defining the same named function function twice going to work?? Ignore the parameter names, the only way the compiler (or anybody, for that matter) is going to know which one to call is by the parameter TYPES.
Was This Post Helpful? 0
  • +
  • -

#6 eburger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-June 09

Re: Web method overloading

Posted 17 June 2009 - 12:41 AM

View PostreCoded, on 16 Jun, 2009 - 10:08 AM, said:

		[WebMethod(MessageName = "Get data by name and part number")]
		[SoapHeader( "WorkEnvironment" )]
		public List<Scratch> GetOpenStatements( string name, string partNumber)
		{



and

		[WebMethod(MessageName = "Get data by last name and part number")]
		[SoapHeader( "WorkEnvironment" )]
		public List<Scratch> GetOpenStatements( string lastName, string partNumber)
		{



The easiest (and if you haven't made a typing error in your parameters, the only) way to make this work is to simply call your methods GetOpenStatementsByName and GetOpenStatementsByLastName, respectively.

As a side note, you seem to be using the MessageName property as the Description property. The latter is used to describe the web method, the first is to create the externally visible name of the web method (normally, this is the name of the method). This might cause problems, too, as method names cannot contain spaces.

Erik
Was This Post Helpful? 0
  • +
  • -

#7 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,594
  • Joined: 16-October 07

Re: Web method overloading

Posted 17 June 2009 - 04:48 AM

View Posteburger, on 17 Jun, 2009 - 01:41 AM, said:

The easiest (and if you haven't made a typing error in your parameters, the only) way to make this work is to simply call your methods GetOpenStatementsByName and GetOpenStatementsByLastName, respectively.


Agree.

Also note that even though you've made methods with identical parameter sigs, it would still fail if you'd done them correctly. Coming into a web service, everything is text. ASP.NET doesn't handle overloading, last time I tried it.
Was This Post Helpful? 0
  • +
  • -

#8 eburger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-June 09

Re: Web method overloading

Posted 17 June 2009 - 05:08 AM

View Postbaavgai, on 17 Jun, 2009 - 03:48 AM, said:

Also note that even though you've made methods with identical parameter sigs, it would still fail if you'd done them correctly. Coming into a web service, everything is text. ASP.NET doesn't handle overloading, last time I tried it.


Actually, I believe you can achieve a form of method overloading using the MethodName property of the WebMethod attribute. Assigning a different name to methods with the same name but different parameter signatures will allow you to use method overloading in your web service class without breaking external (i.e. client-side) functionality.

Using identical parameter signatures isn't method overloading, it's method cloning. Method overloading is "the creation of several methods with the same name which differ from each other in terms of the type of the input and the type of the output of the function" [Wikipedia]. There is no programming language that will support method cloning, as the compiler has no idea which of the methods you wish to call.

Just thought I'd clarify :)

Erik

This post has been edited by eburger: 17 June 2009 - 05:09 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1