How to use multiple WCF services in one client

I'm still learning all the work of WCF, so please carry me here.

I have two self-service services created using C # and VS 2008:
ServiC # 1 Adds two numbers and returns the result.
Service # 2 Returns the square of a number.

I want the client to be able to send two numbers to Service 1, get the amount, and then send the amount to Service 2 and get the square.

I have two generated proxies for both services, and I can use Intellisense on them, so the part supposedly works.

Now how do I configure the app.config file so that I can communicate with both services? Right now, I get an exception every time I try to do this.

[The client works fine if I have only one of the configurations in the application file at a time, and try to call only this server.]

I guess this is a very Nubian question, and the answer probably lies in “structuring the configuration file _____ way”, but Google just doesn't have an example / guide.

Does anyone know how to do this?

Note: Using multiple WCF services on the same client client Although it sounds like a duplicate, NOT what I'm looking for.

Edit: Thanks marc_s, I got his job

In both services running in different applications, I did not need to split the server configuration file, but here is what I did with the client configuration files: first I automatically generated the configuration files using SvrUtil.exe, and then combined them in this way:

<bindings> <wsHttpBinding> <binding> ... </binding> <binding> ... </binding> </wsHttpBinding> </bindings> 

...

  <endpoint> 

...

+5
c # wcf wcf-client
source share
3 answers

If you want to start two services on separate endpoints / ports, follow these steps:

server side:

 <service name="Service1"> <endpoint address="http://localhost:8001/service1.asmx" binding="basicHttpBinding" contract="IService1" /> </service> <service name="Service2"> <endpoint address="http://localhost:8002/service2.asmx" binding="basicHttpBinding" contract="IService2" /> </service> 

client side:

 <client> <endpoint address="http://localhost:8001/service1.asmx" binding="basicHttpBinding" contract="IService1" name="Service1" /> <endpoint address="http://localhost:8002/service2.asmx" binding="basicHttpBinding" contract="IService2" name="Service2" /> </client> 

This should give you two separate endpoints on the server and a client that will talk to both.

Mark

+3
source share

I understand that you asked App.Config to answer, but that might help. I usually start by first setting up client connections programmatically, as it’s easier, and once you get this work, you can transfer it to App.Config.

Here is an example of setting up a WCF client.

 BasicHttpBinding binding = new BasicHttpBinding(); EndpointAddress address = new EndpointAddress(serverURL); MyServiceClient myServiceProxy = new MyServiceClient(binding, address); 

In your App.Config app, you could have something like below.

 <client> <endpoint address="http://localhost/service1.asmx" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="IService1" name="Service1" /> <endpoint address="http://localhost/service2.asmx" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="IService2" name="Service2" /> </client> 
+3
source share

Do you just have a clash of endpoints? Make sure that both services are not configured to listen on the same port number, for example. If you can publish your configuration file (or its sanitized version), that will help.

0
source share

All Articles