/// <summary> /// 创建新的连接对象 /// </summary> /// <param name="address"></param> /// <param name="port"></param> /// <param name="isPolling"></param> /// <param name="pollCapacity"></param> /// <returns></returns> public static INTCPConnection CreatNewConnection(string address, int port, bool isPolling, int pollCapacity) { INTCPConnection driver = null; var remoteEndPoint = new IPEndPoint(IPAddress.Parse(address), port); if (isPolling == true) { //基于连接池的多窗口连接 driver = new SingleConnectionCable(remoteEndPoint, pollCapacity); } else { //单连接 driver = new SingleConnection(remoteEndPoint); } return(driver); }
/// <summary> /// 发送soap消息 并返回结果 /// </summary> /// <param name="msg"></param> /// <returns></returns> public IDataContainer SendSoapMessage(SoapMessage msg) { IDataContainer result = DataContainer.CreateNullDataContainer(); //序列化消息 ISerialize <SoapMessage> iSendMessageSerializer = null; ISerialize <DataContainer> iReturnDataSerializer = new NTCPMessage.Serialize.JsonSerializer <DataContainer>(); iSendMessageSerializer = new NTCPMessage.Serialize.JsonSerializer <SoapMessage>(); //初始化tcp client SingleConnectionCable client = new SingleConnectionCable(new IPEndPoint(IPAddress.Parse(_IPAddress), _Port), 7); client.ReceiveEventHandler += new EventHandler <ReceiveEventArgs>(ReceiveEventHandler); client.ErrorEventHandler += new EventHandler <ErrorEventArgs>(ErrorEventHandler); client.RemoteDisconnected += new EventHandler <DisconnectEventArgs>(DisconnectEventHandler); try { client.Connect(); result = client.SyncSend( (UInt32)MessageType.Json, msg, 20000, iSendMessageSerializer); //sw.Stop(); //Console.WriteLine("Finished. Elapse : {0} ms", sw.ElapsedMilliseconds); } catch (Exception ex) { throw ex; } finally { client.Close(); } return(result); }