Exemplo n.º 1
1
		public void ExportEndpointTest ()
		{
			WsdlExporter we = new WsdlExporter ();

			ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
			se.Binding = new BasicHttpBinding ();
			se.Address = new EndpointAddress ("http://localhost:8080");
			//TEST Invalid name: 5se.Name = "Service#1";
			//se.Name = "Service0";
			//se.ListenUri = new Uri ("http://localhost:8080/svc");

			we.ExportEndpoint (se);

			MetadataSet ms = we.GetGeneratedMetadata ();
			Assert.AreEqual (6, ms.MetadataSections.Count);
			CheckContract_IEchoService (ms, "#eet01");

			WSServiceDescription sd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest");
			CheckServicePort (GetService (sd, "service", "ExportEndpointTest"),
				"BasicHttpBinding_IEchoService", new XmlQualifiedName ("BasicHttpBinding_IEchoService", "http://tempuri.org/"),
				"http://localhost:8080/", "#eet02");

			CheckBasicHttpBinding (sd, "BasicHttpBinding_IEchoService", new XmlQualifiedName ("IEchoService", "http://myns/echo"),
				"Echo", "http://myns/echo/IEchoService/Echo", true, true, "#eet03");
		}
        public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
        {
            var behavior =
                dispatchRuntime.ChannelDispatcher.Host.Description.FindBehavior
                        <WebAuthenticationConfigurationBehavior,
                         WebAuthenticationConfigurationAttribute>(b => b.BaseBehavior);

            if (behavior == null)
                behavior = contractDescription.FindBehavior
                        <WebAuthenticationConfigurationBehavior,
                         WebAuthenticationConfigurationAttribute>(b => b.BaseBehavior);

            if (behavior == null)
                throw new ServiceAuthenticationConfigurationMissingException();

            var authorizationBehavior =
                dispatchRuntime.ChannelDispatcher.Host.Description.FindBehavior
                        <WebAuthorizationConfigurationBehavior,
                        WebAuthorizationConfigurationAttribute>(b => b.BaseBehavior);

            Type authorizationPolicy = null;
            if (authorizationBehavior != null)
                authorizationPolicy = authorizationBehavior.AuthorizationPolicyType;

            foreach (var endpointDispatcher in dispatchRuntime.ChannelDispatcher.Endpoints)
                endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
                    new ServiceAuthenticationInspector(
                        behavior.ThrowIfNull().AuthenticationHandler,
                        behavior.UsernamePasswordValidatorType,
                        behavior.RequireSecureTransport,
                        behavior.Source,
                        authorizationPolicy));
        }
        static Type[] ProcessDescriptionForMsmqIntegration(ServiceEndpoint endpoint, Type[] existingSerializationTypes)
        {
            List<Type> targetSerializationTypes;
            if (existingSerializationTypes == null)
            {
                targetSerializationTypes = new List<Type>();
            }
            else
            {
                targetSerializationTypes = new List<Type>(existingSerializationTypes);
            }

            foreach (OperationDescription operationDesc in endpoint.Contract.Operations)
            {
                foreach (Type type in operationDesc.KnownTypes)
                {
                    // add contract known types to targetSerializationTypes
                    if (!targetSerializationTypes.Contains(type))
                    {
                        targetSerializationTypes.Add(type);
                    }
                }
                // Default document style doesn't work for Integration Transport
                // because messages that SFx layer deals with are not wrapped
                // We need to change style for each operation
                foreach (MessageDescription messageDescription in operationDesc.Messages)
                {
                    messageDescription.Body.WrapperName = messageDescription.Body.WrapperNamespace = null;
                }
            }
            return targetSerializationTypes.ToArray();
        }
Exemplo n.º 4
0
        internal static ClientRuntime BuildProxyBehavior(ServiceEndpoint serviceEndpoint, out BindingParameterCollection parameters)
        {
            parameters = new BindingParameterCollection();
            SecurityContractInformationEndpointBehavior.ClientInstance.AddBindingParameters(serviceEndpoint, parameters);

            AddBindingParameters(serviceEndpoint, parameters);

            ContractDescription contractDescription = serviceEndpoint.Contract;
            ClientRuntime clientRuntime = new ClientRuntime(contractDescription.Name, contractDescription.Namespace);
            clientRuntime.ContractClientType = contractDescription.ContractType;

            IdentityVerifier identityVerifier = serviceEndpoint.Binding.GetProperty<IdentityVerifier>(parameters);
            if (identityVerifier != null)
            {
                clientRuntime.IdentityVerifier = identityVerifier;
            }

            for (int i = 0; i < contractDescription.Operations.Count; i++)
            {
                OperationDescription operation = contractDescription.Operations[i];

                if (!operation.IsServerInitiated())
                {
                    DispatcherBuilder.BuildProxyOperation(operation, clientRuntime);
                }
                else
                {
                    DispatcherBuilder.BuildDispatchOperation(operation, clientRuntime.CallbackDispatchRuntime);
                }
            }

            DispatcherBuilder.ApplyClientBehavior(serviceEndpoint, clientRuntime);
            return clientRuntime;
        }
        public void ApplyConfiguration(ServiceEndpoint endpoint, ChannelEndpointElement channelEndpointElement)
        {
            if (null == endpoint)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint");
            }

            if (null == channelEndpointElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelEndpointElement");
            }

            if (endpoint.GetType() != this.EndpointType)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigInvalidTypeForEndpoint,
                    this.EndpointType.AssemblyQualifiedName,
                    endpoint.GetType().AssemblyQualifiedName));
            }

            // The properties endpoint.Name and this.Name are actually two different things:
            //     - endpoint.Name corresponds to the service endpoint name and is surfaced through
            //       serviceEndpointElement.Name
            //     - this.Name is a token used as a key in the endpoint collection to identify
            //       a specific bucket of configuration settings.
            // Thus, the Name property is skipped here.

            this.OnApplyConfiguration(endpoint, channelEndpointElement);
        }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var item in endpointDispatcher.DispatchRuntime.Operations)
     {
         item.CallContextInitializers.Add(new CultureSettingCallContextInitializer());
     }
 }
 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
     if (clientRuntime != null && clientRuntime.CallbackDispatchRuntime != null && clientRuntime.CallbackDispatchRuntime.UnhandledDispatchOperation != null)
     {
         clientRuntime.CallbackDispatchRuntime.UnhandledDispatchOperation.Invoker = new UnhandledActionOperationInvoker();
     }
 }
 private static void ReplaceDataContractSerializerOperationBehavior(ServiceEndpoint serviceEndpoint)
 {
     foreach (OperationDescription operationDescription in serviceEndpoint.Contract.Operations)
     {
         ReplaceDataContractSerializerOperationBehavior(operationDescription);
     }
 }
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpoint.Contract.Operations.Where(o => Methods.Contains(o.Name)))
     {
         operation.Behaviors.Find<DataContractSerializerOperationBehavior>().DataContractSurrogate = new JavascriptCallbackSurrogate(callbackFactory);
     }
 }
		/// <summary>
		/// Injects the user agent into the service request.
		/// </summary>
		/// <param name="endpoint">The enpoint of the service for which to set the user-agent.</param>
		/// <param name="clientRuntime">The client runtime.</param>
		public override void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
		{
			base.ApplyClientBehavior(endpoint, clientRuntime);
			CookieMessageInspector cmiInspector = new CookieMessageInspector(m_dicAuthenticationCookies);
			clientRuntime.MessageInspectors.Add(cmiInspector);

		}
Exemplo n.º 11
0
		public OrationiSlave()
		{
			Binding binding = new NetTcpBinding(SecurityMode.None);
			EndpointAddress defaultEndpointAddress = new EndpointAddress("net.tcp://localhost:57344/Orationi/Master/v1/");
			EndpointAddress discoveredEndpointAddress = DiscoverMaster();
			ContractDescription contractDescription = ContractDescription.GetContract(typeof(IOrationiMasterService));
			ServiceEndpoint serviceEndpoint = new ServiceEndpoint(contractDescription, binding, discoveredEndpointAddress ?? defaultEndpointAddress);
			var channelFactory = new DuplexChannelFactory<IOrationiMasterService>(this, serviceEndpoint);

			try
			{
				channelFactory.Open();
			}
			catch (Exception ex)
			{
				channelFactory?.Abort();
			}

			try
			{
				_masterService = channelFactory.CreateChannel();
				_communicationObject = (ICommunicationObject)_masterService;
				_communicationObject.Open();
			}
			catch (Exception ex)
			{
				if (_communicationObject != null && _communicationObject.State == CommunicationState.Faulted)
					_communicationObject.Abort();
			}
		}
 void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
 {
     if (endpointDispatcher.DispatchRuntime.ReleaseServiceInstanceOnTransactionComplete)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoBatchingForReleaseOnComplete)));
     if (serviceEndpoint.Contract.SessionMode == SessionMode.Required)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoBatchingForSession)));
 }
Exemplo n.º 13
0
		public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
		{
			foreach (var errorHandler in errorHandlers)
			{
				endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(errorHandler);
			}
		}
		public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
		{
			foreach (DispatchOperation operation in endpointDispatcher.DispatchRuntime.Operations)
			{
				operation.CallContextInitializers.Add(new UnitOfWorkCallContextInitializer());
			}
		}
    protected internal PolicyConversionContext ExportPolicy(ServiceEndpoint endpoint)
    {
      Contract.Requires(endpoint != null);
      Contract.Ensures(Contract.Result<System.ServiceModel.Description.PolicyConversionContext>() != null);

      return default(PolicyConversionContext);
    }
Exemplo n.º 16
0
        protected override IClientMessageFormatter GetRequestClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint)
        {
            if (operationDescription.Behaviors.Find<WebGetAttribute>() != null)
            {
                // no change for GET operations
                return base.GetRequestClientFormatter(operationDescription, endpoint);
            }
            else
            {
                WebInvokeAttribute wia = operationDescription.Behaviors.Find<WebInvokeAttribute>();
                if (wia != null)
                {
                    if (wia.Method == "HEAD")
                    {
                        // essentially a GET operation
                        return base.GetRequestClientFormatter(operationDescription, endpoint);
                    }
                }
            }

            if (operationDescription.Messages[0].Body.Parts.Count == 0)
            {
                // nothing in the body, still use the default
                return base.GetRequestClientFormatter(operationDescription, endpoint);
            }

            return new NewtonsoftJsonClientFormatter(operationDescription, endpoint);
        }
        void IEndpointBehavior.Validate(ServiceEndpoint endpoint)
        {
            if (endpoint == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint");

            ValidateEndpoint(endpoint);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="contractDescription"></param>
 /// <param name="endpoint"></param>
 /// <param name="dispatchRuntime">The runtime object that can be used to modify the default service behavior.</param>
 public void ApplyDispatchBehavior(
     ContractDescription contractDescription,
     ServiceEndpoint endpoint,
     DispatchRuntime dispatchRuntime)
 {
     dispatchRuntime.InstanceProvider = this;   // set the provider to manage service objects instantiation
 }
 void IContractBehavior.ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch)
 {
     if (dispatch.ClientRuntime != null)
     {
         dispatch.ClientRuntime.OperationSelector = new MethodInfoOperationSelector(description, MessageDirection.Output);
     }
 }
Exemplo n.º 20
0
		public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
		{
			foreach (var errorHandler in errorHandlers)
			{
				clientRuntime.CallbackDispatchRuntime.ChannelDispatcher.ErrorHandlers.Add(errorHandler);
			}
		}
		void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
		{
			if (endpoint == null)
				throw new ArgumentNullException ("endpoint");
			if (bindingParameters == null)
				throw new ArgumentNullException ("bindingParameters");
		}
Exemplo n.º 22
0
 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
     var inspector=new ClientHeaderInspector();
     clientRuntime.ClientMessageInspectors.Add(inspector);
     foreach (var op in clientRuntime.Operations)
         op.ParameterInspectors.Add(inspector);
 }
 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
     if (clientRuntime != null)
     {
         clientRuntime.MessageInspectors.Add(this);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="contractDescription"></param>
 /// <param name="endpoint"></param>
 /// <param name="bindingParameters"></param>
 public void AddBindingParameters(
     ContractDescription contractDescription,
     ServiceEndpoint endpoint,
     BindingParameterCollection bindingParameters)
 {
     // empty
 }
        public MethodAndUriTemplateOperationSelector(ServiceEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            this.delegates =
                new Dictionary<string, UriTemplateOperationSelector>();

            var operations = endpoint.Contract.Operations.Select(od => new HttpOperationDescription(od));

            foreach (var methodGroup in operations.GroupBy(od => od.GetWebMethod()))
            {
                UriTemplateTable table = new UriTemplateTable(endpoint.ListenUri);
                foreach (var operation in methodGroup)
                {
                    UriTemplate template = new UriTemplate(operation.GetUriTemplateString());
                    table.KeyValuePairs.Add(
                        new KeyValuePair<UriTemplate, object>(template, operation.Name));

                }

                table.MakeReadOnly(false);
                UriTemplateOperationSelector templateSelector =
                    new UriTemplateOperationSelector(table);
                this.delegates.Add(methodGroup.Key, templateSelector);
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="contractDescription"></param>
 /// <param name="endpoint"></param>
 /// <param name="clientRuntime"></param>
 public void ApplyClientBehavior(
     ContractDescription contractDescription,
     ServiceEndpoint endpoint,
     ClientRuntime clientRuntime)
 {
     // empty
 }
 internal static bool TryAdd(string name, ServiceEndpoint endpoint, out string endpointSectionName)
 {
     if (Configuration == null)
     {
         DiagnosticUtility.FailFast("The TryAdd(string name, ServiceEndpoint endpoint, Configuration config, out string endpointSectionName) variant of this function should always be called first. The Configuration object is not set.");
     }
     bool flag = false;
     string str = null;
     StandardEndpointsSection section = GetSection(Configuration);
     section.UpdateEndpointSections();
     foreach (string str2 in section.EndpointCollectionElements.Keys)
     {
         EndpointCollectionElement element = section.EndpointCollectionElements[str2];
         MethodInfo method = element.GetType().GetMethod("TryAdd", BindingFlags.NonPublic | BindingFlags.Instance);
         if (method != null)
         {
             flag = (bool) method.Invoke(element, new object[] { name, endpoint, Configuration });
             if (flag)
             {
                 str = str2;
                 break;
             }
         }
     }
     endpointSectionName = str;
     return flag;
 }
        public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
        {
            if (serviceEndpoint == null)
                throw new ArgumentNullException("serviceEndpoint");

            if (endpointDispatcher == null)
                throw new ArgumentNullException("endpointDispatcher");

            // Apply URI-based operation selector
            Dictionary<string, string> operationNameDictionary = new Dictionary<string, string>();
            foreach (OperationDescription operation in serviceEndpoint.Contract.Operations)
            {
                try
                {
                    operationNameDictionary.Add(operation.Name.ToLower(), operation.Name);
                }
                catch (ArgumentException)
                {
                    throw new Exception(String.Format("The specified contract cannot be used with case insensitive URI dispatch because there is more than one operation named {0}", operation.Name));
                }
            }
            endpointDispatcher.AddressFilter = new PrefixEndpointAddressMessageFilter(serviceEndpoint.Address);
            endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
            endpointDispatcher.DispatchRuntime.OperationSelector = new UriPathSuffixOperationSelector(serviceEndpoint.Address.Uri, operationNameDictionary);
        }
		void IEndpointBehavior.ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime clientRuntime)
		{
			if (endpoint == null)
				throw new ArgumentNullException ("endpoint");
			if (clientRuntime == null)
				throw new ArgumentNullException ("clientRuntime");
		}
Exemplo n.º 30
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpointDispatcher.DispatchRuntime.Operations)
     {
         operation.CallContextInitializers.Add(_callContextInitializer);
     }
 }
Exemplo n.º 31
0
 /// <summary>
 /// Registra o comportamento para o endpoint informado.
 /// </summary>
 /// <param name="endpoint"></param>
 public static void Register(System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
     endpoint.Require("endpoint").NotNull();
     foreach (OperationDescription od in endpoint.Contract.Operations)
     {
         od.Behaviors.Add(new NetDataContractFormat());
     }
 }
Exemplo n.º 32
0
 /// <summary>
 /// Adds SecurityBehavior to endpoint.
 /// </summary>
 /// <param name="endpoint">Endpoint.</param>
 public void AttachSecurity(System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
     if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
     {
         SecurityBehavior securityBehavior = new SecurityBehavior();
         securityBehavior.CredentialsProvider = _credentialsProvider;
         endpoint.Behaviors.Add(securityBehavior);
     }
 }
Exemplo n.º 33
0
        /// <summary cref="IEndpointBehavior.ApplyClientBehavior" />
        public void ApplyClientBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(this);

            foreach (OperationDescription description in endpoint.Contract.Operations)
            {
                description.Behaviors.Add(new BinaryEncodingMessageFormatter());
            }
        }
Exemplo n.º 34
0
 protected void AttachAddressing(System.ServiceModel.Description.ServiceEndpoint endpoint,
                                 TestTool.Proxies.Event.EndpointReferenceType endpointReference)
 {
     if (endpointReference.ReferenceParameters != null && endpointReference.ReferenceParameters.Any != null)
     {
         Utils.EndpointReferenceBehaviour behaviour = new EndpointReferenceBehaviour(endpointReference);
         endpoint.Behaviors.Add(behaviour);
     }
 }
Exemplo n.º 35
0
 protected virtual void ConfigureEndPoint(System.ServiceModel.Description.ServiceEndpoint point)
 {
     //this.Authentication.ServiceAuthenticationManager = new UserBasicAuthorizationManager();
     //if(point.ListenUri.Scheme == Uri.UriSchemeHttp) {
     //    //webBinding.Security.Mode = WebHttpSecurityMode.None;
     //} else if(point.ListenUri.Scheme == Uri.UriSchemeHttps) {
     //    //webBinding.Security.Mode = WebHttpSecurityMode.Transport;
     //}
 }
Exemplo n.º 36
0
 public CIientBaseInternal(System.ServiceModel.Description.ServiceEndpoint oEp) : base(oEp.Binding, oEp.Address)
 {
     foreach (System.ServiceModel.Description.IEndpointBehavior oBeh in oEp.Behaviors)
     {
         if (!base.Endpoint.Behaviors.Contains(oBeh))
         {
             base.Endpoint.Behaviors.Add(oBeh);
         }
     }
 }
        /// <summary>
        /// 适用身份认证客户端行为
        /// </summary>
        /// <param name="endpoint">服务终结点</param>
        /// <param name="clientRuntime">客户端运行时</param>
        public void ApplyClientBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
#if NET40_OR_GREATER
            //添加消息拦截器
            clientRuntime.MessageInspectors.Add(new AuthenticationMessageInspector());
#endif
#if NETSTANDARD2_0_OR_GREATER
            //添加消息拦截器
            clientRuntime.ClientMessageInspectors.Add(new AuthenticationMessageInspector());
#endif
        }
Exemplo n.º 38
0
        //创建Wcf 服务端代理
        private static T createProxyInstance <T>(Binding binding, EndpointAddress address, NetworkCredential credential)
        {
            Type objType = typeof(T);

            if (objType == null)
            {
                return(default(T));
            }
            try {
                object[] pars           = new object[] { binding, address };
                var      channelFactory = new System.ServiceModel.ChannelFactory <T>(binding, address);
                if (credential != null)
                {
                    channelFactory.Credentials.Windows.ClientCredential = credential;
                }

                System.ServiceModel.Description.ServiceEndpoint endPoint =
                    (System.ServiceModel.Description.ServiceEndpoint)MB.Util.MyReflection.Instance.InvokePropertyForGet(channelFactory, "Endpoint");


                object obj = typeof(System.ServiceModel.ServiceHost).Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior",
                                                                                             true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { false, Int32.MaxValue }, null, null);

                IEndpointBehavior dataSerializerBehavior = obj as IEndpointBehavior;
                endPoint.Behaviors.Add(dataSerializerBehavior);
                endPoint.Behaviors.Add(new EndpointMessageBehavior());

                var clientProxy = channelFactory.CreateChannel();
                if (clientProxy == null)
                {
                    throw new APPException(string.Format("根据类型:{0} 创建实例有误!", typeof(T).FullName));
                }

                return(clientProxy);
            }
            catch (APPException) {
                throw;
            }
            catch (Exception ex) {
                throw new MB.Util.APPException(string.Format("根据类型:{0}创建实例有误!", objType), APPMessageType.SysErrInfo, ex);
            }
        }
Exemplo n.º 39
0
 public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
 {
     //如果是扩展服务器端的MessageInspector,则要附加到EndpointDispacther上了。
     //endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);
 }
Exemplo n.º 40
0
 public void Validate(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint)
 {
 }
Exemplo n.º 41
0
        /// <summary>
        /// host
        /// </summary>
        /// <param name="point"></param>
        /// <param name="debugbehavior"></param>
        /// <param name="throtbehavior"></param>
        /// <param name="bing"></param>
        private void OpenHost(ServicePoint point, ServiceDebugBehavior debugbehavior, ServiceThrottlingBehavior throtbehavior, NetTcpBinding bing, bool EnableBinaryFormatterBehavior)
        {
            ServiceHost host = new ServiceHost(point.Name, new Uri("net.tcp://" + constantSetting.BaseAddress));

            #region behavior
            if (host.Description.Behaviors.Find <ServiceDebugBehavior>() != null)
            {
                host.Description.Behaviors.Remove <ServiceDebugBehavior>();
            }
            if (host.Description.Behaviors.Find <ServiceThrottlingBehavior>() != null)
            {
                host.Description.Behaviors.Remove <ServiceThrottlingBehavior>();
            }

            host.Description.Behaviors.Add(debugbehavior);
            host.Description.Behaviors.Add(throtbehavior);

            //大数据量传输时必须设定此参数
            if (point.MaxItemsInObjectGraph != null)
            {
                if (host.Description.Behaviors.Find <DataContractSerializerOperationBehavior>() != null)
                {
                    host.Description.Behaviors.Remove <DataContractSerializerOperationBehavior>();
                }
                //通过反射指定MaxItemsInObjectGraph属性(传输大数据时使用)
                object obj = typeof(ServiceHost).Assembly.CreateInstance(
                    "System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior"
                    , true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic
                    , null, new object[] { false, (int)point.MaxItemsInObjectGraph }, null, null);
                IServiceBehavior datacontractbehavior = obj as IServiceBehavior;
                host.Description.Behaviors.Add(datacontractbehavior);
            }
            #endregion

            host.AddServiceEndpoint(point.Contract, bing, (point.Address.StartsWith("/") ? point.Address.TrimStart('/') : point.Address));

            //自定义二进制序列化器
            if (EnableBinaryFormatterBehavior)
            {
                System.ServiceModel.Description.ServiceEndpoint spoint = host.Description.Endpoints.Count == 1 ? host.Description.Endpoints[0] : null;
                if (spoint != null && spoint.Behaviors.Find <BinaryFormatterBehavior>() == null)
                {
                    BinaryFormatterBehavior serializeBehavior = new BinaryFormatterBehavior();
                    spoint.Behaviors.Add(serializeBehavior);
                }
            }

            #region 增加拦截器处理
            if (point.Address != "Eltc.Base/FrameWork/Helper/Wcf/LoadBalance/IHeatBeat" && point.Address != "Eltc.Base/FrameWork/Helper/Wcf/Monitor/IMonitorControl")
            {
                int endpointscount          = host.Description.Endpoints.Count;
                WcfParameterInspector wcfpi = new WcfParameterInspector();
                wcfpi.WcfAfterCallEvent += new Wcf.WcfAfterCall((operationName, outputs, returnValue, correlationState, AbsolutePath) =>
                {
                    if (WcfAfterCallEvent != null)
                    {
                        WcfAfterCallEvent(operationName, outputs, returnValue, correlationState, AbsolutePath);
                    }
                });
                wcfpi.WcfBeforeCallEvent += new Wcf.WcfBeforeCall((operationName, inputs, AbsolutePath, correlationState) =>
                {
                    if (WcfBeforeCallEvent != null)
                    {
                        WcfBeforeCallEvent(operationName, inputs, AbsolutePath, correlationState);
                    }
                });
                for (int i = 0; i < endpointscount; i++)
                {
                    if (host.Description.Endpoints[i].Contract.Name != "IMetadataExchange")
                    {
                        int Operationscount = host.Description.Endpoints[i].Contract.Operations.Count;
                        for (int j = 0; j < Operationscount; j++)
                        {
                            host.Description.Endpoints[i].Contract.Operations[j].Behaviors.Add(wcfpi);
                        }
                    }
                }
            }
            #endregion

            #region 注册事件
            //错误状态处理
            host.Faulted += new EventHandler((sender, e) =>
            {
                if (WcfFaultedEvent != null)
                {
                    WcfFaultedEvent(sender, e);
                }
            });
            //关闭状态处理
            host.Closed += new EventHandler((sender, e) =>
            {
                if (WcfClosedEvent != null)
                {
                    WcfClosedEvent(sender, e);
                }

                //如果意外关闭,再次打开监听
                if (isStop)
                {
                    return;
                }

                services.Remove(host);
                OpenHost(point, debugbehavior, throtbehavior, bing, EnableBinaryFormatterBehavior);
            });
            #endregion

            host.Open();
            services.Add(host);
        }
Exemplo n.º 42
0
 void IEndpointBehavior.ApplyClientBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
 {
     clientRuntime.MessageInspectors.Add(new MessageInspector(_username, _password));
 }
Exemplo n.º 43
0
 void IEndpointBehavior.ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
 }
Exemplo n.º 44
0
 /// <summary>
 /// Registra o comportamento para o endpoint informado.
 /// </summary>
 /// <param name="endpoint"></param>
 public static void Register(System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
     endpoint.Behaviors.Add(new SecurityTokenBehavior());
 }
Exemplo n.º 45
0
 public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
 {
     AddInspectorToEndPoint(ref endpointDispatcher);
 }
Exemplo n.º 46
0
 public void Validate(ServiceEndpoint serviceEndpoint)
 {
 }
Exemplo n.º 47
0
 public void ApplyClientBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
 {
     ApplyInspectorsToRuntime(ref clientRuntime);
 }
Exemplo n.º 48
0
 public void ApplyDispatchBehavior(ContractDescription contractDescription, System.ServiceModel.Description.ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
 {
     dispatchRuntime.InstanceProvider = this;
 }
Exemplo n.º 49
0
 public void Validate(ContractDescription contractDescription, System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
 }
Exemplo n.º 50
0
 /// <summary cref="IEndpointBehavior.Validate" />
 public void Validate(System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
     m_transportSupportsEncoding = false; // TBD endpoint.Address.Uri.Scheme == Utils.UriSchemeOpcTcp2;
 }
Exemplo n.º 51
0
 /// <summary cref="IEndpointBehavior.ApplyDispatchBehavior" />
 public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
 }
Exemplo n.º 52
0
 public void ApplyClientBehavior(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
 {
     //此处为Extension附加到ClientRuntime。
     behavior.MessageInspectors.Add(this);
 }
 protected override System.ServiceModel.Description.IEndpointBehavior[] CreateEndpointBehaviors(System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
     return(new IEndpointBehavior[] { this });
 }
Exemplo n.º 54
0
 void IEndpointBehavior.Validate(System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
 }
Exemplo n.º 55
0
 public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior)
 {
 }
Exemplo n.º 56
0
 /// <summary cref="IEndpointBehavior.AddBindingParameters" />
 public void AddBindingParameters(System.ServiceModel.Description.ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
 {
 }
Exemplo n.º 57
0
 public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection parameters)
 {
 }
Exemplo n.º 58
0
 public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher)
 {
 }
Exemplo n.º 59
0
 public void ApplyClientBehavior(ContractDescription contractDescription, System.ServiceModel.Description.ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 {
 }
 void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters)
 {
 }