コード例 #1
0
ファイル: ProxyHelper.cs プロジェクト: NetCoreStack/Wcf
        private ServiceEndpoint PrepareProxyAndGetServiceEndpoint(Type contractType)
        {
            var contractFullNameWithoutAssembly = String.Format("{0}.{1}", contractType.Namespace, contractType.Name);
            var endpointSetting = ConfigurationSettingsManager.GetServiceEndPointSetting(contractFullNameWithoutAssembly);

            if (endpointSetting == null)
            {
                string assemblyName = contractType.Assembly.GetName().Name;
                endpointSetting = ConfigurationSettingsManager.GetServiceEndPointSetting(assemblyName);
            }

            Type   bindingType = DefaultBindingType;
            string bindingConfigurationName = DefaultBindingConfigurationName;
            string endpointBaseAddress      = DefaultEndpointBaseUrl;

            if (endpointSetting != null)
            {
                if (!string.IsNullOrEmpty(endpointSetting.Binding))
                {
                    bindingType = Type.GetType((endpointSetting.Binding == "CustomBinding"
                        ? String.Format(
                                                    "System.ServiceModel.Channels.{0}, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                                                    endpointSetting.Binding)
                        : String.Format(
                                                    "System.ServiceModel.{0}, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                                                    endpointSetting.Binding)));
                }
                if (!string.IsNullOrEmpty(endpointSetting.BindingConfiguration))
                {
                    bindingConfigurationName = endpointSetting.BindingConfiguration;
                }
                if (!string.IsNullOrEmpty(endpointSetting.BaseAddress))
                {
                    endpointBaseAddress = endpointSetting.BaseAddress;
                }
            }

            var binding = string.IsNullOrEmpty(bindingConfigurationName)
                    ? (Binding)Activator.CreateInstance(bindingType)
                    : (Binding)Activator.CreateInstance(bindingType, bindingConfigurationName);

            var endPoint = new ServiceEndpoint(ContractDescription.GetContract(contractType),
                                               binding,
                                               new EndpointAddress(EndpointAddressResolver.Resolve(contractType, endpointBaseAddress)));

            if (DataContractSurrogateBehavior != null)
            {
                foreach (var operation in endPoint.Contract.Operations)
                {
                    operation.OperationBehaviors.Add(DataContractSurrogateBehavior);
                }
            }

            if (ClientMessageInspectorBehavior != null)
            {
                endPoint.EndpointBehaviors.Add((IEndpointBehavior)ClientMessageInspectorBehavior);
            }

            return(endPoint);
        }
コード例 #2
0
        public string Resolve(Type contractType, string endpointBaseUrl)
        {
            string assemblyName = contractType.Assembly.GetName().Name;
            string baseAddress  = ConfigurationSettingsManager.GetServiceEndPointBaseAddress(assemblyName);

            if (string.IsNullOrEmpty(baseAddress))
            {
                return(string.Format("{0}/{1}.{2}", endpointBaseUrl.TrimEnd('/'), contractType.Name.Substring(1).TrimStart('/'), "svc"));
            }

            return(string.Format("{0}/{1}.{2}", baseAddress.TrimEnd('/'), contractType.Name.Substring(1).TrimStart('/'), "svc"));
        }
コード例 #3
0
ファイル: ProxyHelper.cs プロジェクト: NetCoreStack/Wcf
        public ProxyHelper()
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            EndpointAddressResolver        = new DefaultEndpointAddressResolver();
            ClientMessageInspectorBehavior = new ClientMessageInspectorBehavior();
            DataContractSurrogateBehavior  = new DefaultSurrogateBehavior();
            DefaultEndpointBaseUrl         = ConfigurationSettingsManager.GetApplicationSetting("DefaultEndpointBaseUrl");
            var bindingName = String.IsNullOrEmpty(ConfigurationSettingsManager.GetApplicationSetting("DefaultBindingType")) ? "BasicHttpBinding" : ConfigurationSettingsManager.GetApplicationSetting("DefaultBindingType");

            DefaultBindingType = Type.GetType((bindingName == "CustomBinding" ? String.Format("System.ServiceModel.Channels.{0}, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", bindingName) : String.Format("System.ServiceModel.{0}, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", bindingName)));
            DefaultBindingConfigurationName = String.IsNullOrEmpty(ConfigurationSettingsManager.GetApplicationSetting("DefaultBindingConfigurationName")) ? string.Empty : ConfigurationSettingsManager.GetApplicationSetting("DefaultBindingConfigurationName");
            ChannelFactoryCache             = new ConcurrentDictionary <Type, Lazy <ChannelFactory> >();
        }