user2318170 February 2016

How to crate WCF object of 2 WCF service dynamically based on endpoint name?

I am consuming 2 WCF service in 1 WCF service.

using WcfService.Server1;
using WcfService.Server2;

I am calling a function that is returning endpoint name of suitable WCF service based on some logic. How to create object of WCF service based on endpoint name dynamically?

In below code I created WCF object of "Server1" WCF service but suppose method returns endpoint name "Server2Endpoint" then it would be a problem because I am referring WcfService.Server1

WcfService.Server1.MatrixCalculationClient Proxy1 = new WcfService.Server1.MatrixCalculationClient("Server1Endpoint");

Answers


Igor Labutin February 2016

I assume that both WCF services implements same interface, e.g. IWCFService.

Then I believe you will have to use either your own proxy class (which implements IWCFService independently of Server1 or Server2) or construct channel manually using ChannelFactory<IWCFService>.

In both cases you can pass name of the endpoint to the proper constructors and then everything will work if app.config file contains correct definition of these endpoints (same contract).

Post Status

Asked in February 2016
Viewed 2,236 times
Voted 14
Answered 1 times

Search




Leave an answer