我正在尝试与WCF实现服务器/客户端通信,并且在双工通信中遇到了麻烦,但是我认为你需要一个服务器和2个客户端,只有2个客户端可以通过服务器相互通信?! ?
有没有办法只与WCF进行2台机器/进程通信? 以便客户端直接与服务器通信?
到目前为止我做了什么:
创建包含Interfaces,Classes,OperationContract / ServiceContract / ServiceBehaviour的项目
创建项目,这是“服务器”,它基本上就是这个代码:
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>
创建一个客户端项目,然后在其中添加一个ServiceReference到服务器localhost:8080/WCFServer_Service
我实际上不需要第二个第二个客户端,我只想在服务器/客户端之间推送数据。