6

I am still learning the whole WCF thing, so please bear with me here.

What I have is two self hosted services created using C# and VS 2008:
Service # 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 in two numbers to Service 1, get the sum and then send the sum in to Service 2 and get the square.

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

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

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

I suppose this is a very noobish question, and the answer probably is "structure the config file in _____ manner", but Google simply does not seem to have an example/guide.

Anyone know how to do this?

Note: Consume multiple WCF services from one client client Though sounds like a duplicate is NOT what I am looking for.

Edit: Thanks to marc_s, I got it working

With both the services running in different apps, I did not need to split the server config file, but here is what I did with the client config files: First auto-generated the config files using SvrUtil.exe and then merged them in this way:

<bindings>
  <wsHttpBinding>

    <binding>
    ...
    </binding>

    <binding>
    ...
    </binding>

  </wsHttpBinding>
</bindings>

...

  <endpoint>

...

2
  • +1 - voted up to bump you from 1,999 to 2K rep so you can now EDIT other people's answers! woot! Commented Nov 7, 2009 at 11:30
  • @Jeremy: Haha thanks! It is unbelievable how long it was stuck at 1999. Commented Nov 8, 2009 at 5:11

3 Answers 3

5

I realise you have asked for an App.Config answer but figure this might help. I would normally start by configuring the client connections programatically first, since it's simpler, and once you have got that working you could move it to your App.Config.

Here's an exmaple of how to configure a WCF client.

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

You could then have something like the below in your App.Config.

<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>
4

If you want to run the two services on separate endpoints / ports, do something like this:

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>

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

Marc

1
  • Thanks, that worked! There were so many permutations to merge the config files, that I just decided to ask, rather than cover all permutations :P Commented Apr 1, 2009 at 15:53
0

Do you just have a clash of endpoints? Make sure that both services aren't configured to listen on the same port number for example. If you could post your config file (or a sanitised version of it) that would help.

2
  • I do have them both running on the same port, but I am able to call service A from Service B, both listening to port 8000. Suppose I do run them on different ports, how do i structure the app.config? Commented Mar 26, 2009 at 15:51
  • Under <system.serviceMode><services> you'd have multiple <service> elements, and so on. You can't just copy both complete config sections, you have to merge them.
    – David M
    Commented Mar 26, 2009 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.