public IRemoteSide CreateInstance() { IRemoteSide ret = null; var cm = diContainer.GetLazyBoundInstance <IWCFConfigManager>().Value; var clientServiceInstance = diContainer.GetLazyBoundInstance <IRemoteSideCommunicationHandler>().Value; ret = new WCFServiceHost(diContainer, (IRemoteSideCommunicationContract)clientServiceInstance, new Uri(cm.ClientServiceAddress)); clientServiceInstance.AssignRemoteSide(ret); return(ret); }
public IRemoteSide CreateInstance() { IRemoteSide ret = null; // init binding var binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; var cm = diContainer.GetLazyBoundInstance <IWCFConfigManager>().Value; WCFHelper.ApplyWCFBindingLimits( binding, cm.ClientServiceMaxSizeInBytes, cm.ClientServiceTimeoutInSecs); // init endpoint address var endpointAddress = new EndpointAddress(cm.ClientServiceAddress); // create context var clientServiceInstance = diContainer.GetLazyBoundInstance <IRemoteSideCommunicationHandler>().Value; var instanceContext = new InstanceContext((IRemoteSideCommunicationContract)clientServiceInstance); // create client var cscc = new WCFServiceClient(instanceContext, binding, endpointAddress); clientServiceInstance.AssignRemoteSide(cscc); // init client WCFHelper.ApplyWCFEndpointLimits(cscc.Endpoint, cm.ClientServiceMaxItemsInObjectGraph); ret = cscc; return(ret); }
public WCFServiceHost(IDIContainer diContainer, IRemoteSideCommunicationContract clientServiceContractInstance, Uri clientServiceAddress) : base(clientServiceContractInstance, clientServiceAddress) { this.ID = RemoteSideIDType.Parse(Guid.NewGuid().ToString()); this.diContainer = diContainer; this.clientServiceContractInstance = clientServiceContractInstance; cm = diContainer.GetLazyBoundInstance <IWCFConfigManager>(); ApplyConfiguration(); this.AddServiceEndpoint( ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), String.Concat(new Uri(cm.Value.ClientServiceAddress).OriginalString, "/mex")); this.Closed += new EventHandler(clientServiceHost_StateChanged); this.Closing += new EventHandler(clientServiceHost_StateChanged); this.Faulted += new EventHandler(clientServiceHost_StateChanged); this.Opened += new EventHandler(clientServiceHost_StateChanged); this.Opening += new EventHandler(clientServiceHost_StateChanged); }
public virtual RemoteResponse ExecuteRequest(RemoteRequest request, Type callableTypeAttribute, Type callableFuncAttribute) { if (request == null) { throw new ArgumentNullException("request"); } if (callableTypeAttribute == null) { throw new ArgumentNullException("callableTypeAttribute"); } if (callableFuncAttribute == null) { throw new ArgumentNullException("callableFuncAttribute"); } RemoteResponse ret = new RemoteResponse(); try { // get type Type interfaceType; interfaceType = TypeHelper.GetType(request.ExecuteOnRemoteSideOperation.InterfaceType, VersionMismatchCheckerAssemblyResolver, null); if (interfaceType != null) { MethodInfo methodInfo = TypeHelper.GetMethodInfo(interfaceType, request.ExecuteOnRemoteSideOperation.MethodName, request.ExecuteOnRemoteSideOperation.Parameters); if (methodInfo != null) { string calledMethodName = String.Concat(interfaceType.Name, "+", methodInfo.Name); System.Diagnostics.Debug.WriteLine("{0}Call to: {1}", (request.RemoteID != null) ? String.Concat("[", request.RemoteID, "] ") : String.Empty, calledMethodName); // sanity checks if (!TypeHelper.HasCustomAttribute(interfaceType, callableTypeAttribute)) { throw new InvalidOperationException(String.Format("Method {0} in type {1} called, but type not marked with {2}!", methodInfo.Name, interfaceType.Name, callableTypeAttribute)); //LOCSTR } var attrs = TypeHelper.GetCustomAttributes(methodInfo, callableFuncAttribute); if (attrs.Length != 1) { throw new InvalidOperationException(String.Format("Method {0} in type {1} called, but method not marked with {2}!", methodInfo.Name, interfaceType.Name, callableFuncAttribute)); //LOCSTR } // get instance var lbInstance = diContainer.GetLazyBoundInstance(interfaceType); if (lbInstance.Value != null) { object instance = lbInstance.Value; // call method ret.ReturnValue = methodInfo.Invoke(instance, request.ExecuteOnRemoteSideOperation.Parameters); } else { throw new InvalidOperationException(string.Format("Interface {0} not available in DIContainer!", interfaceType.Name)); //LOCSTR } } else { throw new InvalidOperationException(string.Format("Method {0} not found with parameters: {1}!", request.ExecuteOnRemoteSideOperation.MethodName, string.Join(",", request.ExecuteOnRemoteSideOperation.Parameters))); //LOCSTR } } else { throw new InvalidOperationException(string.Format("Interface {0} not found!", request.ExecuteOnRemoteSideOperation.InterfaceType)); //LOCSTR } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("While processing request: {1}{0}{1}{2}", request, Environment.NewLine, ex); //LOCSTR TargetInvocationException tex = ex as TargetInvocationException; if ((tex != null) && (tex.InnerException != null)) { ex = tex.InnerException; } ret.ReturnValue = ex; } return(ret); }
public new void Open() { base.Open(); System.Diagnostics.Debug.WriteLine("Listening on: {0} (WCF)", diContainer.GetLazyBoundInstance <IWCFConfigManager>().Value.ClientServiceAddress); }