如何从一个客户端占用多个WCF服务多个、客户端、WCF

2023-09-04 00:26:42 作者:儿子,看爹给你摇个妈

我仍然在学习的整个WCF的东西,所以请和我一起在这里承受的。

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

我有什么是用C#和VS 2008中创建两个自托管服务: 服务#1两个数相加并返回结果。 服务#2返回一个数的平方。

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.

我希望客户端能够发送两个号码服务1,得到的总和,然后发送之和为服务2,让广场上。

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.

现在我如何配置我app.config文件,这样我可以同时与服务进行通信?现在,我每一次我尝试这样做,会得到一个异常。

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.]

我想这是一个非常noobish的问题,答案很可能是结构配置文件的 _ 的方式,但谷歌似乎根本没有有一个示例/指南。

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?

注:http://stackoverflow.com/questions/487662/consume-multiple-wcf-services-from-one- 客户端虽然听起来像一个重复的是我找不是的。

Note: http://stackoverflow.com/questions/487662/consume-multiple-wcf-services-from-one- client Though sounds like a duplicate is NOT what I am looking for.

编辑:感谢marc_s,我得到了它的工作

Thanks to marc_s, I got it working

通过这两个服务在不同的应用程序运行,我并不需要拆分服务器配置文件,但这里是我做的客户端配置文件:使用SvrUtil.exe一是自动生成的配置文件,然​​后它们合并以这种方式:

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>

...           

...

推荐答案

如果你想运行两个服务在不同的终端/端口,做这样的事情:

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

服务器端:

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

马克·