Implementing Web method Overload in ASP.net Web Services

In the below methods i will implement two method with Same name but the Signature will be different.
  1. public class SumWebService: System.Web.Services.WebService   
  2. {  
  3.     //1st Method  
  4.     ----------------------------------[WebMethod]  
  5.     public int Sum(int number1, int number2)   
  6.     {  
  7.         return number1 + number2;  
  8.     }  
  9.     //2nd Method  
  10.     ------------------------------[WebMethod]  
  11.     public int Sum(int number1, int number2, int number3)   
  12.     {  
  13.         return number1 + number2 + number3;  
  14.     }  
  15. }  
when we will build this Soultion  it will build successfully but when we will view the Service. it will Show error ike this.

[ Both Int32 Sum(Int32, Int32, Int32) and Int32 Sum(Int32, Int32) use the message name 'Sum'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods. ] 
  1. Two Overcome this error we will use MessageName Propery of Webmethod to uniquely Identify the Method.  
  2. {  
  3.     //1st Method  
  4.     ----------------------------------[WebMethod(MessageName = "Sum2Numbers")]  
  5.     public int Sum(int number1, int number2)   
  6.     {  
  7.         return number1 + number2;  
  8.     }  
  9.     //2nd Method  
  10.     ------------------------------[WebMethod]  
  11.     public int Sum(int number1, int number2, int number3)   
  12.     {  
  13.         return number1 + number2 + number3;  
  14.     }  
After making the corrections in the method when we again run this Service it show a different Error.

Service 'WebServicesDemo.SumWebService' does not conform to WS-I Basic Profile v1.1. Please examine each of the normative statement violations below. To turn off conformance check set the ConformanceClaims property on corresponding WebServiceBinding attribute to WsiClaims.None.

R2304: Operation name overloading in a wsdl:portType is disallowed by the Profile. A wsdl:portType in a DESCRIPTION MUST have operations with distinct values for their name attributes. Note that this requirement applies only to the wsdl:operations within a given wsdl:portType. A wsdl:portType may have wsdl:operations with names that are the same as those found in other wsdl:portTypes.

Operation 'Sum' on portType 'CalculatorWebServiceSoap' from namespace 'http://www.xyz.com/webservices'.
To make service conformant please make sure that all web methods belonging to the same binding have unique names.

changing WebServiceBinding attribute on the web service class will fix this Issue
-----------------------------------------------------------------------------------------------------------------

FROM - [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
TO - [WebServiceBinding(ConformsTo = WsiProfiles.None)]

Ebook Download
View all
Learn
View all