public TResponse GetResponse <TResponse>(object request, string queueName) { Guard.AgainstNull(request, nameof(request)); Guard.AgainstNullOrEmptyString(queueName, nameof(queueName)); TransportFrame frame; var responseTypeName = typeof(TResponse).FullName; using (var stream = _serializer.Serialize(request)) { var type = request.GetType(); frame = new TransportFrame { QueueName = queueName, AssemblyQualifiedName = type.AssemblyQualifiedName, MessageType = type.FullName, Message = stream.ToBytes() }; } using (var stream = _serializer.Serialize(frame)) { if (!_requestSocket.TrySendFrame(_timeout, stream.ToBytes()) || !_requestSocket.TryReceiveFrameBytes(_timeout, out var bytes)) { throw NetMQException.For(responseTypeName, frame.MessageType, Resources.CommunicationException); } using (var ms = new MemoryStream(bytes)) { frame = (TransportFrame)_serializer.Deserialize(_transportFrameType, ms); } using (var ms = new MemoryStream(frame.Message)) { if (frame.MessageType.Equals(responseTypeName, StringComparison.InvariantCultureIgnoreCase)) { return((TResponse)_serializer.Deserialize(typeof(TResponse), ms)); } throw new NetMQException(string.Format(Resources.ServerException, ((Response)_serializer.Deserialize(_responseType, ms)).Exception)); } } }