public override BindingElement Clone() { CustomTextMessageBindingElement res = new CustomTextMessageBindingElement(); res.MediaType = MediaType; res.Encoding = Encoding; res.MessageVersion = MessageVersion; res.readerQuotas = readerQuotas; return(res); }
public static int Main(string[] args) { try { string iniFileName = ServiceManager.SharedInstance.IniFileName; if (!File.Exists(iniFileName)) { ServiceManager.LogMessage("[OpcServiceHost] No servers.ini file found '{0}'. Terminated.", iniFileName); return(1); } PrepareConsole(); ServiceManager.SharedInstance.Init(); host = new ServiceHost(typeof(OPCService), new Uri(ServiceManager.SharedInstance.ServiceUrl)); int numEndpoints = 0; ServiceManager.SharedInstance.EnumServers((address, serverUrl, parameters) => { if (ConnectionManager.SharedInstance.RegisterServer(serverUrl)) { ServiceEndpoint endpoint; string codepage = parameters["codepage"]; if (codepage != null) { ICollection <BindingElement> bindingElements = new List <BindingElement>(); HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement(); textBindingElement.Encoding = codepage; bindingElements.Add(textBindingElement); bindingElements.Add(httpBindingElement); CustomBinding customBinding = new CustomBinding(bindingElements); endpoint = host.AddServiceEndpoint(typeof(Service), new BasicHttpBinding() { MaxReceivedMessageSize = ServiceManager.SharedInstance.MaxReceivedMessageSize }, address); endpoint.Binding = customBinding; } else // Default UTF-8 { endpoint = host.AddServiceEndpoint(typeof(Service), new BasicHttpBinding() { MaxReceivedMessageSize = ServiceManager.SharedInstance.MaxReceivedMessageSize }, address); } ServiceManager.SharedInstance.RegisterEndpoint(endpoint, serverUrl, parameters); ServiceManager.LogMessage("[OpcServiceHost] Created SOAP service endpoint {0}", endpoint.Address); numEndpoints++; } }); if (numEndpoints == 0) { ServiceManager.LogMessage("[OpcServiceHost] No endpoints configured."); return(1); } foreach (var operation in host.Description.Endpoints[0].Contract.Operations) { operation.Behaviors.Add(new CustomInvokerBehavior()); } ConnectionManager.SharedInstance.StartWatchDog(); host.Open(); Console.CancelKeyPress += Console_CancelKeyPress; ServiceManager.LogMessage("[OpcServiceHost] Starting service host. Press Ctrl+Break for terminate..."); terminate.WaitOne(); ConnectionManager.SharedInstance.Shutdown(); host.Close(); ServiceManager.LogMessage("[OpcServiceHost] Stopped service host."); return(0); } catch (Exception ex) { ServiceManager.LogMessage("[OpcServiceHost] Unhandled exception thrown {0}", ex.ToString()); ServiceManager.LogMessage("[OpcServiceHost] Terminated."); return(2); } }