public static IExplicitBytesClient CreateClient(Binding binding, Guid uuid, string address) { var bindingInfo = EndpointMapper.WcfToRpc(address); bindingInfo.EndPoint = CanonizeEndpoint(bindingInfo); var client = new ExplicitBytesClient(uuid, bindingInfo); //NOTE: applying any authentication on local IPC greatly slows down start up of many simulatanious service bool skipAuthentication = binding.Authentication == RPC_C_AUTHN.RPC_C_AUTHN_NONE && bindingInfo.Protseq == RpcProtseq.ncalrpc; if (skipAuthentication) { client.AuthenticateAsNone(); } else { client.AuthenticateAs(null, binding.Authentication == RPC_C_AUTHN.RPC_C_AUTHN_NONE ? ExplicitBytesClient.Anonymous : ExplicitBytesClient.Self, binding.Authentication == RPC_C_AUTHN.RPC_C_AUTHN_NONE ? RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_NONE : RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, binding.Authentication); } return(client); }
public static IExplicitBytesServer CreateHost(Binding binding, string address, Guid uuid) { var host = new ExplicitBytesServer(uuid); var endpointBinding = EndpointMapper.WcfToRpc(address); string endPoint = CanonizeEndpoint(endpointBinding); host.AddProtocol(binding.ProtocolTransport, endPoint, binding.MaxConnections); host.AddAuthentication(binding.Authentication); return(host); }
//TODO: split RpcProxyRouter and RpcCallbackProxy public ClientRuntime(string address, ServiceEndpoint endpoint, bool callback = false, InstanceContext context = null, Guid customUuid = default(Guid), Type generatedProxyType = null) { _endpoint = endpoint; _binding = endpoint._binding; _serializer = _binding.Serializer; _typeOfService = endpoint._contractType; _context = context; if (_context != null && _context._useSynchronizationContext) { _syncContext = SynchronizationContext.Current; } _generatedProxyType = generatedProxyType; _address = address; _operations = DispatchTableFactory.GetOperations(_typeOfService); _uuid = EndpointMapper.CreateUuid(_address, _typeOfService); if (customUuid != Guid.Empty) // callback proxy { _uuid = customUuid; } var serviceContract = AttributesReader.GetServiceContract(_typeOfService); //TODO: null check only for duplex callback, really should always be here if (serviceContract != null && serviceContract.SessionMode == SessionMode.Required) { _session = Guid.NewGuid().ToString(); } //TODO: allow to be initialized with pregenerated proxy var realProxy = new RpcRealProxy(_typeOfService, this, _endpoint, _encoder); _remote = realProxy.GetTransparentProxy(); _client = RpcRequestReplyChannelFactory.CreateClient(_binding, _uuid, _address); foreach (var behavior in _endpoint.Behaviors) { behavior.ApplyClientBehavior(_endpoint, this); } }
public ServiceEndpoint AddServiceEndpoint(Type contractType, Binding binding, string address) { var uri = new Uri(address, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) { address = _baseAddress + address; } var uuid = EndpointMapper.CreateUuid(address, contractType); bool expectDuplexInitialization = false; var service = AttributesReader.GetServiceContract(contractType); if (service.CallbackContract != null) { expectDuplexInitialization = true; } RpcTrace.TraceEvent(TraceEventType.Start, "Start adding service endpoint for {0} at {1}", contractType, address); var endpoint = base.CreateEndpoint(contractType, binding, address, uuid); _endpointDispatchers.Add(new RpcEndpointDispatcher(_service, endpoint, expectDuplexInitialization)); return(endpoint); }
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); }