How can I use two methods with the same name in WCF?

Possible duplicate:
why can't you overload the method in WCF?

I am working on a project in which I use WCF services. My problem is that in the wcf service I have one method called "Display ()" which is used by me client1. Now I want to add another method with the same name, but with one parameter, i.e. "Display (line name)" so that new clinet2 can use the new method, and old client1 can use the old method. how can i achieve this. here is the code i wrote. 10Q in advance.

namespace ContractVersioningService
{
  [ServiceContract]
  public interface IService1 
  {
    [OperationContract]
    string Display();

    [OperationContract]
    string GoodNight();
  }     
}

namespace ContractVersioningService
{
   public class Service1 : IService1
   {
     public string Display()
     {
        return "Good Morning";          
     }

     public string GoodNight()
     {
        return "Good Night";
     }
   }
}    

namespace ContractVersioningService
{
  [ServiceContract(Namespace = "ContractVersioningService/01", Name =      "ServiceVersioning")]
  public interface IService2 : IService1
  {
     [OperationContract]
     string Disp(string greet);
  }
}

namespace ContractVersioningService
{

   public class Service2 : Service1, IService2
   {
      public string Display(string name)
      {
         return name;
      }

      public string Disp(string s)
      {
         return s;
      }
   }
}
+5
source share
2 answers
    Why WCF doesnot support method overloading directly ?
  • WSDL ( OOP). WCF WSDL, , .

    WCF / WSDL. Microsoft , -.

  • WCF , .

    - Name. ,

        [OperationContract(Name="Integers")]
        int Display(int a,int b)
        [OperationContract(Name="Doubles")]
        double Display(double a,double b)
    

, wsdl

     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName=
    "ServiceRef.IService1")]
  public interface IService1
   {
       [System.ServiceModel.OperationContractAttribute(
       Action="http://tempuri.org/Service1/AddNumber",
       ReplyAction="http://tempuri.org/IHelloWorld/IntegersResponse")]                   
       int Display(int a,int b)

       [System.ServiceModel.OperationContractAttribute(
       Action="http://tempuri.org/IHelloWorld/ConcatenateStrings",
       ReplyAction="http://tempuri.org/Service1/DoublesResponse")]
       double Display(double a,double b)
  }
+11

, , .

:

  • ( , , , ), . , # [OperationContract(Name = "distinctname")].

  • - , . , , . , /, .

+7

All Articles