How to use generated proxy and contract for client as they are in service when using "Operation Overloading" in WCF

We can use generated proxy and contract for client as they are, but we need to rework them to provide overloading on the client side. Rename the methods on the imported contract and the proxy to the overloaded names, and make sure the proxy class makes calls on the internal proxy using the overloaded methods. Then use the Name property on the imported contract on the client side to alias and overload the methods, matching the imported operation names.

 

[ServiceContract]

interface IUser

{

    [OperationContract(Name= "AddUser")]

    int Add(string arg1, string arg2);

 

    [OperationContract(Name = "AddUserWithEmail")]

    int Add(string arg1, string arg2 , string arg3);

}

 

class UserClient : ClientBase<IUser>, IUser

{

    public int Add(string arg1, string arg2)

    {

        return Channel.Add(arg1, arg2);

    }

    public int Add(string arg1, string arg2 , string arg3)

    {

        return Channel.Add(string arg1, string arg2, string arg3);

    }

    //Rest of the proxy

} 

Now we can use readable overloaded operations.

 

UserClient proxy = new UserClient();

int UserID = proxy.Add("mukesh", "123456");

int UserIDWithEmail = proxy.Add("mukesh", "123456", "[email protected]");

proxy.Close();

Next Recommended Reading Service Contract in WCF