public byte[] Invoke(IRpcCallInfo call, Type contractType, byte[] arg) { var messageRequest = (MessageRequest)_encoder.ReadObject(new MemoryStream(arg), typeof(MessageRequest)); Message response = invokeContract(call, messageRequest, contractType); var stream = new MemoryStream(); _encoder.WriteObject(stream, response); return stream.ToArray(); }
public byte[] Invoke(IRpcCallInfo call, Type contractType, byte[] arg) { var messageRequest = (MessageRequest)_encoder.ReadObject(new MemoryStream(arg), typeof(MessageRequest)); Message response = invokeContract(call, messageRequest, contractType); var stream = new MemoryStream(); _encoder.WriteObject(stream, response); return(stream.ToArray()); }
/// <summary> /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can /// subscribe to the OnExecute event. /// </summary> public virtual byte[] Execute(IRpcCallInfo call, byte[] input) { RpcExecuteHandler proc = _handler; if (proc != null) { return(proc(call, input)); } return(null); }
private Message invokeContract(IRpcCallInfo call, MessageRequest request, Type contractType) { OperationDispatchBase operation; bool operationExists = _operations.IdToOperation.TryGetValue(request.Operation, out operation); if (!operationExists) { var error = new ActionNotSupportedException(string.Format("Server endpoint {0} with contract {1} does not supports operation with id = {2}. Check that client and server use the same version of contract and binding. ", _endpoint._address, contractType, request.Operation)); var faultMessage = new Message(); faultMessage = makeFault(error, faultMessage); return(faultMessage); } OperationContext operationContext = SetupOperationConext(call, request, contractType); Func <Message> invokeAction = () => { OperationContext.Current = operationContext; if (_concurrency == ConcurrencyMode.Single) { lock (this) { return(invokeContract(operation, request)); } } return(invokeContract(operation, request)); }; if (operation.Operation.IsOneWay) { Task task = Tasks.Factory.StartNew(invokeAction); task.ContinueWith(x => RpcTrace.Error(x.Exception), TaskContinuationOptions.OnlyOnFaulted); return(new Message()); } else { return(invokeAction()); } }
private OperationContext SetupOperationConext(IRpcCallInfo call, MessageRequest request, Type contractType) { var operationContext = new OperationContext { SessionId = request.Session }; if (request.Session != null) { if (_duplex) { lock (_clients) { RpcCallbackChannelFactory channelFactory = null; bool contains = _clients.TryGetValue(request.Session, out channelFactory); if (!contains) { var contract = AttributesReader.GetServiceContract(contractType); channelFactory = new RpcCallbackChannelFactory(_endpoint._binding, contract.CallbackContract, new Guid(request.Session), true); _clients[request.Session] = channelFactory; } var callbackBindingInfo = EndpointMapper.WcfToRpc(_endpoint._address); if (!call.IsClientLocal) { //BUG: callbacks accross network does not work //callbackAddress.NetworkAddr = call.ClientAddress } callbackBindingInfo.EndPoint += request.Session.Replace("-", ""); operationContext.SetGetter(_clients[request.Session], EndpointMapper.RpcToWcf(callbackBindingInfo)); } } } return(operationContext); }
private OperationContext SetupOperationConext(IRpcCallInfo call, MessageRequest request, Type contractType) { var operationContext = new OperationContext { SessionId = request.Session }; if (request.Session != null) { if (_duplex) { lock (_clients) { RpcCallbackChannelFactory channelFactory = null; bool contains = _clients.TryGetValue(request.Session, out channelFactory); if (!contains) { var contract = AttributesReader.GetServiceContract(contractType); channelFactory = new RpcCallbackChannelFactory(_endpoint._binding, contract.CallbackContract, new Guid(request.Session), true); _clients[request.Session] = channelFactory; } var callbackBindingInfo = EndpointMapper.WcfToRpc(_endpoint._address); if (!call.IsClientLocal) { //BUG: callbacks accross network does not work //callbackAddress.NetworkAddr = call.ClientAddress } callbackBindingInfo.EndPoint += request.Session.Replace("-", ""); operationContext.SetGetter(_clients[request.Session], EndpointMapper.RpcToWcf(callbackBindingInfo)); } } } return operationContext; }
private Message invokeContract(IRpcCallInfo call, MessageRequest request, Type contractType) { OperationDispatchBase operation; bool operationExists = _operations.IdToOperation.TryGetValue(request.Operation, out operation); if (!operationExists) { var error = new ActionNotSupportedException(string.Format("Server endpoint {0} with contract {1} does not supports operation with id = {2}. Check that client and server use the same version of contract and binding. ", _endpoint._address, contractType, request.Operation)); var faultMessage = new Message(); faultMessage = makeFault(error, faultMessage); return faultMessage; } OperationContext operationContext = SetupOperationConext(call, request, contractType); Func<Message> invokeAction = () => { OperationContext.Current = operationContext; if (_concurrency == ConcurrencyMode.Single) { lock (this) { return invokeContract(operation, request); } } return invokeContract(operation, request); }; if (operation.Operation.IsOneWay) { Task task = Tasks.Factory.StartNew(invokeAction); task.ContinueWith(x => RpcTrace.Error(x.Exception), TaskContinuationOptions.OnlyOnFaulted); return new Message(); } else { return invokeAction(); } }
static byte[] api_OnExecute(IRpcCallInfo client, byte[] input) { byte[] resp = new byte[input.Length * 10]; return resp; }
static byte[] api_OnExecute(IRpcCallInfo client, byte[] input) { byte[] resp = new byte[input.Length * 10]; return(resp); }
/// <summary> /// Can be over-ridden in a derived class to handle the incomming RPC request, or you can /// subscribe to the OnExecute event. /// </summary> public virtual byte[] Execute(IRpcCallInfo call, byte[] input) { RpcExecuteHandler proc = _handler; if (proc != null) { return proc(call, input); } return null; }