Hungry Mind
Hungry Mind

Reputation: 113

How to host same contract with 2 different configurations as 2 services in WCF?

I've developed a contract for WCF. It has a database connection. So I like to connect with 2 different databases with 2 different services. So how can I host that contract with 2 different configurations (like database name, username, password) as 2 services in 2 different addresses?

For Example I have a contract called DataHandler. Now I have to register them as 2 services on a system, First service can access databse1 and second service can access database2

I can't give database1 & database2 as a parameter from client application. So how to solve this problem? Can I give any parameter to service contract from hosting server?

Upvotes: 0

Views: 125

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

Use one service with single endpoint and single configuration and deploy this service to two different applications each providing correct configuration. It seems like a strange solution but it is the simplest one and in many scenarios also the correct one. It also provides the best separation between two configurations.

Upvotes: 1

Related Questions