Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF双工连接(无第二个客户端的服务器-客户端通信)_C#_Wcf - Fatal编程技术网

C# WCF双工连接(无第二个客户端的服务器-客户端通信)

C# WCF双工连接(无第二个客户端的服务器-客户端通信),c#,wcf,C#,Wcf,我正在尝试使用WCF实现服务器/客户端通信,但在我看来,您需要一个服务器和两个客户端,只有这两个客户端可以通过服务器相互通信 是否有办法只与WCF进行2台机器/进程通信? 这样客户端就可以直接与服务器通信了 到目前为止我所做的: 创建包含接口、类、OperationContract/ServiceContract/ServiceBehavior的项目 创建项目,即“服务器”,其基本代码如下: static void Main(string[] args) { using (var ser

我正在尝试使用WCF实现服务器/客户端通信,但在我看来,您需要一个服务器和两个客户端,只有这两个客户端可以通过服务器相互通信

是否有办法只与WCF进行2台机器/进程通信? 这样客户端就可以直接与服务器通信了

到目前为止我所做的:

创建包含接口、类、OperationContract/ServiceContract/ServiceBehavior的项目

创建项目,即“服务器”,其基本代码如下:

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>
static void Main(字符串[]args)
{
使用(var serviceHost=newservicehost(typeof(ServiceInbound)))
{
//打开主机并开始侦听传入的消息。
Open();
//保持服务运行,直到按下Enter键。
WriteLine(“服务准备就绪”);
Console.WriteLine(“按Enter键终止服务”);
Console.ReadLine();
}
}
创建一个客户端项目,并在其中向服务器添加一个ServiceReference
localhost:8080/WCFServer\u服务


实际上,我不需要第二个客户端,我只想在服务器/客户端之间推送数据。

您需要的是客户端回调。客户机为服务调用提供回调函数


请参见

双工连接允许服务器回调到打开连接的客户端计算机。您与第二个客户端的事情偏离了轨道,WCF duplex不允许客户端彼此通信,至少不允许直接通信。