I have two ServiceReference in my C# app (generated via VisualStudio): ServiceReference1 and ServiceReference2.
Both have the same methods and class names. Their interfaces differ in some methods, but I want only to use methods which have the same interface on both.
How to use them dynamically?
Example:
ServiceReference1.Client clnt1 = new ServiceReference1.Client();
ServiceReference2.Client clnt2 = new ServiceReference2.Client();
string result = "";
if (type == 1)
result = clnt1.calculate();
else
result = clnt2.calculate();
string result2 = "";
if (type == 1)
result2 = clnt1.calculate2();
else
result2 = clnt2.calculate2();
//and so on...
I'm searching for something like this...
ServiceReference1.Client clnt = null;
if (type == 1)
clnt = new ServiceReference1.Client();
else
clnt = new (ServiceReference1.Client)ServiceReference2.Client();
string result = clnt.calculate();
string result2 = clnt.calculate2();
//and so on...
Since ServiceReference1.Client
owns all methods of ServiceReference2.Client
(and some more) I thought it should be possible. But it doesn't work.
Using var
for the clnt
variable also doesn't work, because the Clients are globally defined in the class and var
can only be used inside methods.