1

我有以下代码:

客户端:

public bool Connect(string IPAdress, string Port, string UniqueName)
{
        try
        {
            EndpointAddress address = new EndpointAddress(new Uri("net.tcp://"+IPAdress+":"+Port+"/"+UniqueName));

            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;
            binding.TransferMode = TransferMode.Streamed;
            binding.MaxReceivedMessageSize = 1024 * 1024 * 64;
            m_Factory = new DuplexChannelFactory<IServerService>(this, binding, address);

            m_Service = m_Factory.CreateChannel();
            return true;
        }
        catch (Exception ex)
        {
            //log error
            return false;
        }
}

服务器端

 public void Start(string Port, string UniqueName) {
        Uri baseAddress = new Uri("net.tcp://127.0.0.1:" + Port + "/" + UniqueName);
        NetTcpBinding binding = new NetTcpBinding();
        binding.Security.Mode = System.ServiceModel.SecurityMode.None;
        binding.MaxReceivedMessageSize = 1024 * 1024 * 64;
        binding.TransferMode = System.ServiceModel.TransferMode.Streamed;
        try
        {
            m_ServiceHost = new System.ServiceModel.ServiceHost(this, baseAddress);

            m_ServiceHost.AddServiceEndpoint(typeof(IServerService), binding, baseAddress);
            m_ServiceHost.Open();
        }
        catch (Exception ex)
        {

        }
    }

我尝试将绑定创建为缓冲,但是当我尝试发送 FileStream 时,服务器端使实例为空,因为我读到我需要使用流传输模式。

我在该行的客户端收到以下异常

m_Service = m_Factory.CreateChannel();

合同需要双工,但绑定“NetTcpBinding”不支持它或未正确配置以支持它。

4

0 回答 0