当前位置: 首页>>代码示例>>C#>>正文


C# CustomBinding.CanBuildChannelListener方法代码示例

本文整理汇总了C#中System.ServiceModel.Channels.CustomBinding.CanBuildChannelListener方法的典型用法代码示例。如果您正苦于以下问题:C# CustomBinding.CanBuildChannelListener方法的具体用法?C# CustomBinding.CanBuildChannelListener怎么用?C# CustomBinding.CanBuildChannelListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.Channels.CustomBinding的用法示例。


在下文中一共展示了CustomBinding.CanBuildChannelListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddMetadataEndpoint

        void AddMetadataEndpoint(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher, bool debugMode)
        {
            Uri baseAddress = endpoint.Address.Uri;
            if (baseAddress == null)
            {
                return;
            }

            ServiceHostBase host = endpointDispatcher.ChannelDispatcher.Host;

            UriBuilder builder = new UriBuilder(baseAddress);
            builder.Path += builder.Path.EndsWith("/", StringComparison.OrdinalIgnoreCase)
                ? (WebScriptClientGenerator.GetMetadataEndpointSuffix(debugMode))
                : ("/" + WebScriptClientGenerator.GetMetadataEndpointSuffix(debugMode));
            EndpointAddress metadataAddress = new EndpointAddress(builder.Uri);

            foreach (ServiceEndpoint serviceEndpoint in host.Description.Endpoints)
            {
                if (EndpointAddress.UriEquals(serviceEndpoint.Address.Uri, metadataAddress.Uri, true, false))//  ignoreCase //  includeHostNameInComparison 
                {
                    throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new InvalidOperationException(SR2.GetString(SR2.JsonNoEndpointAtMetadataAddress, this.GetType().ToString(), serviceEndpoint.Address, serviceEndpoint.Name, host.Description.Name)));
                }
            }

            HttpTransportBindingElement transportBindingElement;
            HttpTransportBindingElement existingTransportBindingElement = endpoint.Binding.CreateBindingElements().Find<HttpTransportBindingElement>();

            if (existingTransportBindingElement != null)
            {
                transportBindingElement = (HttpTransportBindingElement)existingTransportBindingElement.Clone();
            }
            else
            {
                if (baseAddress.Scheme == "https")
                {
                    transportBindingElement = new HttpsTransportBindingElement();
                }
                else
                {
                    transportBindingElement = new HttpTransportBindingElement();
                }
            }

            transportBindingElement.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            transportBindingElement.TransferMode = TransferMode.Buffered;
            transportBindingElement.MaxBufferSize = MaxMetadataEndpointBufferSize;
            transportBindingElement.MaxReceivedMessageSize = MaxMetadataEndpointBufferSize;
            Binding metadataBinding = new CustomBinding(
                new WebScriptMetadataMessageEncodingBindingElement(),
                transportBindingElement);
            BindingParameterCollection parameters = host.GetBindingParameters(endpoint);

            // build endpoint dispatcher
            ContractDescription metadataContract = ContractDescription.GetContract(typeof(ServiceMetadataExtension.IHttpGetMetadata));
            OperationDescription metadataOperation = metadataContract.Operations[0];
            EndpointDispatcher metadataEndpointDispatcher = new EndpointDispatcher(metadataAddress, metadataContract.Name, metadataContract.Namespace);
            DispatchOperation dispatchOperation = new DispatchOperation(metadataEndpointDispatcher.DispatchRuntime, metadataOperation.Name, metadataOperation.Messages[0].Action, metadataOperation.Messages[1].Action);
            dispatchOperation.Formatter = new WebScriptMetadataFormatter();
            dispatchOperation.Invoker = new SyncMethodInvoker(metadataOperation.SyncMethod);
            metadataEndpointDispatcher.DispatchRuntime.Operations.Add(dispatchOperation);
            metadataEndpointDispatcher.DispatchRuntime.SingletonInstanceContext = new InstanceContext(host, new WebScriptClientGenerator(endpoint, debugMode, !String.IsNullOrEmpty(this.JavascriptCallbackParameterName)));
            metadataEndpointDispatcher.DispatchRuntime.InstanceContextProvider = new SingletonInstanceContextProvider(metadataEndpointDispatcher.DispatchRuntime);

            // build channel dispatcher
            IChannelListener<IReplyChannel> listener = null;
            if (metadataBinding.CanBuildChannelListener<IReplyChannel>(parameters))
            {
                listener = metadataBinding.BuildChannelListener<IReplyChannel>(metadataAddress.Uri, parameters);
            }
            ChannelDispatcher metadataChannelDispatcher = new ChannelDispatcher(listener);
            metadataChannelDispatcher.MessageVersion = MessageVersion.None;
            metadataChannelDispatcher.Endpoints.Add(metadataEndpointDispatcher);

            host.ChannelDispatchers.Add(metadataChannelDispatcher);
        }
开发者ID:uQr,项目名称:referencesource,代码行数:76,代码来源:WebScriptEnablingBehavior.cs

示例2: BuildChannelListener


//.........这里部分代码省略.........
                    datagramContractName = contract.Name;
                }

                System.Collections.IList endpointTypes = GetSupportedChannelTypes(contract);
                if (!endpointTypes.Contains(typeof(IReplyChannel)))
                {
                    reply = false;
                }
                if (!endpointTypes.Contains(typeof(IReplySessionChannel)))
                {
                    replySession = false;
                }
                if (!endpointTypes.Contains(typeof(IInputChannel)))
                {
                    input = false;
                }
                if (!endpointTypes.Contains(typeof(IInputSessionChannel)))
                {
                    inputSession = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexChannel)))
                {
                    duplex = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexSessionChannel)))
                {
                    duplexSession = false;
                }
            }

            if ((sessionContractName != null) && (datagramContractName != null))
            {
                string text = SR.GetString(SR.SFxCannotRequireBothSessionAndDatagram3, datagramContractName, sessionContractName, binding.Name);
                Exception error = new InvalidOperationException(text);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }

            List<Type> supportedChannelTypes = new List<Type>();
            if (input)
            {
                supportedChannelTypes.Add(typeof(IInputChannel));
            }
            if (inputSession)
            {
                supportedChannelTypes.Add(typeof(IInputSessionChannel));
            }
            if (reply)
            {
                supportedChannelTypes.Add(typeof(IReplyChannel));
            }
            if (replySession)
            {
                supportedChannelTypes.Add(typeof(IReplySessionChannel));
            }
            if (duplex)
            {
                supportedChannelTypes.Add(typeof(IDuplexChannel));
            }
            if (duplexSession)
            {
                supportedChannelTypes.Add(typeof(IDuplexSessionChannel));
            }
            // now we know what channel types we can use to support the contracts at this ListenUri
            Type returnValue = DispatcherBuilder.MaybeCreateListener(true, supportedChannelTypes.ToArray(), binding, parameters,
                                                                     listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, serviceHost.ServiceThrottle, out result,
                                                                     supportContextSession && sessionContractName != null);
            if (result == null)
            {
                // we put a lot of work into creating a good error message, as this is a common case
                Dictionary<Type, byte> setOfChannelTypesSupportedByBinding = new Dictionary<Type, byte>();
                if (binding.CanBuildChannelListener<IInputChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IInputChannel), 0);
                }
                if (binding.CanBuildChannelListener<IReplyChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IReplyChannel), 0);
                }
                if (binding.CanBuildChannelListener<IDuplexChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IDuplexChannel), 0);
                }
                if (binding.CanBuildChannelListener<IInputSessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IInputSessionChannel), 0);
                }
                if (binding.CanBuildChannelListener<IReplySessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IReplySessionChannel), 0);
                }
                if (binding.CanBuildChannelListener<IDuplexSessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IDuplexSessionChannel), 0);
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateListenerException(
                                                                              setOfChannelTypesSupportedByBinding.Keys, supportedChannelTypes, originalBinding.Name));
            }
            return returnValue;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:DispatcherBuilder.cs

示例3: BuildChannelListener

 private System.Type BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, bool supportContextSession, out IChannelListener result)
 {
     Uri uri;
     string str;
     Binding binding = stuff.Endpoints[0].Binding;
     CustomBinding binding2 = new CustomBinding(binding);
     BindingParameterCollection parameters = stuff.Parameters;
     this.GetBaseAndRelativeAddresses(serviceHost, listenUri, binding2.Scheme, out uri, out str);
     InternalDuplexBindingElement internalDuplexBindingElement = null;
     InternalDuplexBindingElement.AddDuplexListenerSupport(binding2, ref internalDuplexBindingElement);
     bool flag = true;
     bool flag2 = true;
     bool flag3 = true;
     bool flag4 = true;
     bool flag5 = true;
     bool flag6 = true;
     string name = null;
     string str3 = null;
     for (int i = 0; i < stuff.Endpoints.Count; i++)
     {
         ContractDescription contract = stuff.Endpoints[i].Contract;
         if (contract.SessionMode == SessionMode.Required)
         {
             name = contract.Name;
         }
         if (contract.SessionMode == SessionMode.NotAllowed)
         {
             str3 = contract.Name;
         }
         IList supportedChannelTypes = GetSupportedChannelTypes(contract);
         if (!supportedChannelTypes.Contains(typeof(IReplyChannel)))
         {
             flag = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IReplySessionChannel)))
         {
             flag2 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IInputChannel)))
         {
             flag3 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IInputSessionChannel)))
         {
             flag4 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IDuplexChannel)))
         {
             flag5 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IDuplexSessionChannel)))
         {
             flag6 = false;
         }
     }
     if ((name != null) && (str3 != null))
     {
         Exception exception = new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCannotRequireBothSessionAndDatagram3", new object[] { str3, name, binding2.Name }));
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
     }
     List<System.Type> requiredChannels = new List<System.Type>();
     if (flag3)
     {
         requiredChannels.Add(typeof(IInputChannel));
     }
     if (flag4)
     {
         requiredChannels.Add(typeof(IInputSessionChannel));
     }
     if (flag)
     {
         requiredChannels.Add(typeof(IReplyChannel));
     }
     if (flag2)
     {
         requiredChannels.Add(typeof(IReplySessionChannel));
     }
     if (flag5)
     {
         requiredChannels.Add(typeof(IDuplexChannel));
     }
     if (flag6)
     {
         requiredChannels.Add(typeof(IDuplexSessionChannel));
     }
     System.Type type = MaybeCreateListener(true, requiredChannels.ToArray(), binding2, parameters, uri, str, listenUriMode, serviceHost.ServiceThrottle, out result, supportContextSession && (name != null));
     if (result != null)
     {
         return type;
     }
     Dictionary<System.Type, byte> dictionary = new Dictionary<System.Type, byte>();
     if (binding2.CanBuildChannelListener<IInputChannel>(new object[0]))
     {
         dictionary.Add(typeof(IInputChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IReplyChannel>(new object[0]))
     {
         dictionary.Add(typeof(IReplyChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IDuplexChannel>(new object[0]))
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:DispatcherBuilder.cs


注:本文中的System.ServiceModel.Channels.CustomBinding.CanBuildChannelListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。