Reputation: 34234
I have a question about consequences of extension of a method on the server and I appreciate if you help me.
Let's suppose the following. I have a method in a facade on the server:
public void SaveSomeData(SomeDataEntity[] someDataEntities)
{
someDataLocator.SaveData(someDataEntities);
}
And call it from a client like:
public void SaveSomeData(SomeDataEntity[] someDataEntities)
{
this.Invoke("SaveSomeData", new object[] { someDataEntities });
}
Now, I need to extend it to
public void SaveSomeData(SomeDataEntity[] someDataEntities, string mode)
{
someDataLocator.SaveData(someDataEntities, mode);
}
I need to provide a backward compatibility. So, if a user uses an old version and he tries to call this method with only single param, what will happen? Will server guess that this is the same method and call it? If yes, will "mode" string (second argument) be null or empty? Or it just will throw an exception saying that client tries to invoke an non-existing function. Is it possible to solve this problem without duplicating the method with both one and two arguments.
Upvotes: 0
Views: 64
Reputation: 34234
I have found an answer by experiment.
It understands that this is the necessary method and invokes it. When I invoke this method from an old client having the single argument in facade then
public void SaveSomeData(SomeDataEntity[] someDataEntities, string mode)
{
someDataLocator.SaveData(someDataEntities, mode);
}
executes on the server with mode
equal to null
.
So, I can easily process it in "someDataLocator". Backward compatibility is provided itself.
Upvotes: 1
Reputation: 14687
WCF doesn't support method overloading because the WSDL doesn't allow to have two methods with same name. You can achieve it by providing OperationContract with Name attribute on overloaded methods.
[OperationContract(Name="SaveSomeDataDefault")]
public void SaveSomeData(SomeDataEntity[] someDataEntities)
{
this.Invoke("SaveSomeData", new object[] { someDataEntities });
}
[OperationContract(Name="SaveSomeDataWithMode")]
public void SaveSomeData(SomeDataEntity[] someDataEntities, string mode)
{
someDataLocator.SaveData(someDataEntities, mode);
}
But this also not a good practice as it will lead you to the problem for debugging tracing etc. The practice is to keep separate methods rather using overloading in WCF.
Upvotes: 2
Reputation: 10211
You can simply mark old signature as obsolete, then call new signature with a string empty
[Obsolete]
public void SaveSomeData(SomeDataEntity[] someDataEntities)
{
someDataLocator.SaveData(someDataEntities, string.Empty);
}
Upvotes: 2