Example #1
0
        internal static ServerStartInfo GetServerStartInfo(
            string serviceName,
            string extraInfo,
            WcfServiceConfig service)
        {
            var log = GetStartInfo <ServerStartInfo>(extraInfo);

            log.WcfService  = service;
            log.ServiceName = serviceName;
            return(log);
        }
Example #2
0
        public WcfServiceConfig GetWcfService(string serviceType, string serviceContractVersion, string machineIP)
        {
            try
            {
                var wcfServices = WcfConfig.GetServices().Where(s => s.ServiceTypeName == serviceType).ToList();
                var wcfService = wcfServices.Where(s => machineIP.Contains(s.ServerMachineIP) || s.ServerMachineIP == "*").FirstOrDefault();
                if (wcfService == null)
                {
                    Warning("Adhesive.DistributedService.Config", "WcfConfigService.GetWcfService", string.Format("GetWcfService没获取到Service信息,参数为{0},{1},{2}", serviceType, serviceContractVersion, machineIP));
                    return null;
                }

                var service = new WcfServiceConfig
                {
                    ServiceType = serviceType,
                    ServiceBehaviorXml = wcfService.ServiceBehaviorXml != null ? wcfService.ServiceBehaviorXml.ToString() : "",
                };

                var endpoints = (from ep in WcfConfig.GetServiceEndpoints()
                                 where ep.ServiceTypeName == serviceType
                                 && (ep.ContractVersion == serviceContractVersion || ep.ContractVersion == "*")
                                 && (ep.ServerMachineIP == wcfService.ServerMachineIP || ep.ServerMachineIP == "*")
                                 select new WcfServiceEndpointConfig
                                 {
                                     EndpointBehaviorXml = ep.ServiceEndpointBehaviorXml != null ? ep.ServiceEndpointBehaviorXml.ToString() : "",
                                     EndpointBindingName = ep.ServiceEndpointBindingName,
                                     EndpointName = ep.ServiceEndpointName,
                                     EndpointPort = ep.ServiceEndpointPort,
                                     ServiceContractType = ep.ContractTypeName
                                 }).ToList();

                if (endpoints == null)
                {
                    Warning("Adhesive.DistributedService.Config", "WcfConfigService.GetWcfService", string.Format("GetWcfService没获取到Endpoint信息,参数为{0},{1},{2}", serviceType, serviceContractVersion, machineIP));
                    return null;
                }
                service.Endpoints = endpoints;
                foreach (var endpoint in service.Endpoints)
                {
                    var binding = WcfConfig.GetBindings().Single(b => b.BindingName == endpoint.EndpointBindingName);
                    if (binding == null)
                    {
                        Warning("Adhesive.DistributedService.Config", "WcfConfigService.GetWcfService", string.Format("GetWcfService没获取到Binding信息,参数为{0},{1},{2}", serviceType, serviceContractVersion, machineIP));
                        return null;
                    }
                    else
                    {
                        endpoint.EndpointBindingType = binding.BindingType;
                        endpoint.EndpointBindingXml = binding.BindingXml != null ? binding.BindingXml.ToString() : "";
                        endpoint.EndpointProtocol = binding.BindingProtocol;
                    }
                }

                return service;
            }
            catch (Exception ex)
            {
                Error("Adhesive.DistributedService.Config", "WcfConfigService.GetWcfService", string.Format("GetWcfService出错:{0},参数为{1},{2},{3}", ex.ToString(), serviceType, serviceContractVersion, machineIP));
                return null;
            }
        }