简体   繁体   English

WCF双工连接(没有第二个客户端的服务器<->客户端通信)

[英]WCF duplex connection (Server <-> Client communication without 2nd Client)

I am trying to implement a Server/Client communication with WCF and have stumbled accross duplex communication, but as I see it you would need a Server and 2 clients and only the 2 clients can communicate over the server with each other?!? 我正在尝试与WCF实现服务器/客户端通信,并且偶然遇到了双工通信,但是正如我看到的那样,您将需要一个服务器和2个客户端,并且只有2个客户端可以通过服务器彼此通信?!

Is there a way to only get a 2 machines/process communication with WCF? 有没有一种方法只能与WCF进行2台机器/过程通信? So that the client communicates directly with the Server? 这样客户端可以直接与服务器通信?

What I have done so far: 到目前为止,我所做的是:

Create Project with contains the Interfaces, Classes, OperationContract/ServiceContract/ServiceBehaviour 创建包含以下内容的项目接口,类,OperationContract / ServiceContract / ServiceBehaviour

Create Project which is the "Server" its basically just this code: 创建“服务器”项目,基本上就是以下代码:

static void Main(string[] args)
{
    using (var serviceHost = new ServiceHost(typeof(ServiceInbound)))
    {
        // Open the host and start listening for incoming messages.
        serviceHost.Open();
        // Keep the service running until the Enter key is pressed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press the Enter key to terminate service.");
        Console.ReadLine();
    }
}

<system.serviceModel>
  <services>
    <service name="WCFLibary.ServiceInbound" behaviorConfiguration="WCFLibaryMEXBehavior">
      <endpoint address="service" binding="wsDualHttpBinding" contract="WCFLibary.IServiceInbound"/>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/WCFServer_Service"/>
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="WCFLibaryMEXBehavior">
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

Create a client Project and in there Add a ServiceReference to the server localhost:8080/WCFServer_Service 创建一个客户端项目,然后在其中添加一个ServiceReference到服务器localhost:8080/WCFServer_Service

I actually dont need a 2nd second client, I just want to push data between the server/client. 我实际上不需要第二个客户端,我只想在服务器/客户端之间推送数据。

What your looking for is client callbacks. 您需要的是客户端回调。 The client provides a callback function with the service call. 客户端通过服务调用提供回调函数。

See this page on MSDN 在MSDN上查看此页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM