robertk
robertk

Reputation: 2461

Share WCF classes on client when using same WCF-service on different servers

I got a WCF-service that is deployed on both production and test service. Nothing seperates them except the backend databases.

And got a WPF-client that have a reference to both services.

To call them I've to use seperate clients. For example the test server:

NewsServiceTest.NewsNewsServiceClient client = new NewsServiceClient("BasicHttpsBinding_INewsService");

And the production server:

NewsServiceProd.NewsServiceClient client = new NewsServiceClient("BasicHttpsBinding_INewsService");

The clients has exactly the same methods, so my questions is: Is it possible to have the same base client? I don't want to duplicate code when calling the the same methods but on different clients.

Upvotes: 0

Views: 233

Answers (1)

tom redfern
tom redfern

Reputation: 31750

Having the same base client to call the same endpoint hosted in different environments is fundamental to WCF.

Any services framework which didn't allow this in my opinion would be broken.

So yes, it is possible. Just pass in the service URL into the service client:

client.Endpoint.Address = new EndpointAddress("whichever URL I want"); 

Upvotes: 3

Related Questions