void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext)
        {
            bool createdNew;
            MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(endpointContext, out createdNew);

            TransportBindingElement.ExportWsdlEndpoint(exporter, endpointContext, this.WsdlTransportUri, encodingBindingElement.MessageVersion.Addressing);
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

#pragma warning suppress 56506 // Microsoft, these properties cannot be null in this context
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

#pragma warning suppress 56506 // Microsoft, CustomBinding.Elements never be null
            TransportBindingElement transportBindingElement = GetBindingElements(context).Find <TransportBindingElement>();

            bool transportHandledExternaly = (transportBindingElement != null) && !StateHelper.IsRegisteredTransportBindingElement(importer, context);
            if (transportHandledExternaly)
            {
                return;
            }

#pragma warning suppress 56506 // Microsoft, these properties cannot be null in this context
            WsdlNS.SoapBinding soapBinding = (WsdlNS.SoapBinding)context.WsdlBinding.Extensions.Find(typeof(WsdlNS.SoapBinding));
            if (soapBinding != null && transportBindingElement == null)
            {
                CreateLegacyTransportBindingElement(importer, soapBinding, context);
            }

            // Try to import WS-Addressing address from the port
            if (context.WsdlPort != null)
            {
                ImportAddress(context, transportBindingElement);
            }
        }
        protected TransportChannelFactory(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory) : base(context.Binding)
        {
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> collection = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (collection.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MultipleMebesInParameters")));
            }
            if (collection.Count == 1)
            {
                this.messageEncoderFactory = collection[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            if (this.messageEncoderFactory != null)
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            else
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
            }
        }
        public override IChannelFactory <TChannel> BuildChannelFactory <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
            }

            if (!CanBuildChannelFactory <TChannel>(context))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.ChannelTypeNotSupported, typeof(TChannel)), nameof(TChannel)));
            }

            ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>();
            if (ReaderQuotas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.EncodingBindingElementDoesNotHandleReaderQuotas));
            }

            TransportBindingElement transportBindingElement = null;

            if (context.RemainingBindingElements != null)
            {
                transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>();
            }

            if (transportBindingElement != null)
            {
                MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize;
            }

            IChannelFactory <TChannel> result = BuildChannelFactoryCore <TChannel>(context);

            return(result);
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }
            TransportBindingElement transportBindingElement = GetBindingElements(context).Find <TransportBindingElement>();

            if ((transportBindingElement == null) || StateHelper.IsRegisteredTransportBindingElement(importer, context))
            {
                SoapBinding soapBinding = (SoapBinding)context.WsdlBinding.Extensions.Find(typeof(SoapBinding));
                if ((soapBinding != null) && (transportBindingElement == null))
                {
                    CreateLegacyTransportBindingElement(importer, soapBinding, context);
                }
                if (context.WsdlPort != null)
                {
                    ImportAddress(context, transportBindingElement);
                }
            }
        }
Example #6
0
        private void VerifyTransportMode(BindingContext context)
        {
            TransferMode            transferMode;
            TransportBindingElement element = context.RemainingBindingElements.Find <TransportBindingElement>();

            if ((element != null) && element.ManualAddressing)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("ManualAddressingNotSupported")));
            }
            ConnectionOrientedTransportBindingElement element2 = element as ConnectionOrientedTransportBindingElement;
            HttpTransportBindingElement element3 = element as HttpTransportBindingElement;

            if (element2 != null)
            {
                transferMode = element2.TransferMode;
            }
            else if (element3 != null)
            {
                transferMode = element3.TransferMode;
            }
            else
            {
                transferMode = TransferMode.Buffered;
            }
            if (transferMode != TransferMode.Buffered)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("TransferModeNotSupported", new object[] { transferMode, base.GetType().Name })));
            }
        }
 protected TransportBindingElement(TransportBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     this.manualAddressing       = elementToBeCloned.manualAddressing;
     this.maxBufferPoolSize      = elementToBeCloned.maxBufferPoolSize;
     this.maxReceivedMessageSize = elementToBeCloned.maxReceivedMessageSize;
 }
        protected TransportChannelFactory(TransportBindingElement bindingElement, BindingContext context,
                                          MessageEncoderFactory defaultMessageEncoderFactory)
            : base(context.Binding)
        {
            ManualAddressing        = bindingElement.ManualAddressing;
            MaxBufferPoolSize       = bindingElement.MaxBufferPoolSize;
            _maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;

            Collection <MessageEncodingBindingElement> messageEncoderBindingElements
                = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncoderBindingElements.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.MultipleMebesInParameters));
            }
            else if (messageEncoderBindingElements.Count == 1)
            {
                MessageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                MessageEncoderFactory = defaultMessageEncoderFactory;
            }

            if (null != MessageEncoderFactory)
            {
                _messageVersion = MessageEncoderFactory.MessageVersion;
            }
            else
            {
                _messageVersion = MessageVersion.None;
            }
        }
        internal static IChannelListener CreateChannelListener <TChannel>(TransportBindingElement transport)
            where TChannel : class, IChannel
        {
            Binding binding = new CustomBinding(transport);

            return(binding.BuildChannelListener <TChannel>());
        }
Example #10
0
        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext)
        {
            bool flag;
            MessageEncodingBindingElement element = this.FindMessageEncodingBindingElement(endpointContext, out flag);

            TransportBindingElement.ExportWsdlEndpoint(exporter, endpointContext, "http://schemas.microsoft.com/soap/peer", element.MessageVersion.Addressing);
        }
Example #11
0
        bool ImportTransport(MetadataImporter importer, TransportBindingElement bindingElement,
                             XmlElement transportPolicy)
        {
            XmlElement algorithmSuite, layout;

            if (!PolicyImportHelper.FindPolicyElement(
                    importer, transportPolicy,
                    new QName("AlgorithmSuite", PolicyImportHelper.SecurityPolicyNS),
                    false, true, out algorithmSuite) ||
                !PolicyImportHelper.FindPolicyElement(
                    importer, transportPolicy,
                    new QName("Layout", PolicyImportHelper.SecurityPolicyNS),
                    false, true, out layout))
            {
                return(false);
            }

            bool foundUnknown = false;

            foreach (var node in transportPolicy.ChildNodes)
            {
                var e = node as XmlElement;
                if (e == null)
                {
                    continue;
                }
                importer.AddWarning("Unknown policy assertion: {0}", e.OuterXml);
                foundUnknown = true;
            }

            return(!foundUnknown);
        }
        void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
        {
            if (endpointContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");
            }

#pragma warning suppress 56506 // [....], endpointContext.Endpoint is never null
            if (endpointContext.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext.Binding");
            }

            if (endpointContext.Endpoint.Binding is CustomBinding)
            {
                BindingElementCollection elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;

                Binding binding;
                TransportBindingElement transport = elements.Find <TransportBindingElement>();

                if (transport is HttpTransportBindingElement)
                {
                    if (WSHttpBindingBase.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (WSDualHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (BasicHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                    else if (NetHttpBinding.TryCreate(elements, out binding))
                    {
                        SetBinding(endpointContext.Endpoint, binding);
                    }
                }
                else if (transport is MsmqTransportBindingElement && NetMsmqBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
                else if (transport is NamedPipeTransportBindingElement && NetNamedPipeBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning disable 0618
                else if (transport is PeerTransportBindingElement && NetPeerTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
#pragma warning restore 0618
                else if (transport is TcpTransportBindingElement && NetTcpBinding.TryCreate(elements, out binding))
                {
                    SetBinding(endpointContext.Endpoint, binding);
                }
            }
        }
 protected TransportBindingElement(
     TransportBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     manual_addressing     = elementToBeCloned.manual_addressing;
     max_buffer_pool_size  = elementToBeCloned.max_buffer_pool_size;
     max_recv_message_size = elementToBeCloned.max_recv_message_size;
 }
 protected TransportBindingElement(
     TransportBindingElement other)
     : base(other)
 {
     manual_addressing     = other.manual_addressing;
     max_buffer_pool_size  = other.max_buffer_pool_size;
     max_recv_message_size = other.max_recv_message_size;
 }
        void IPolicyExportExtension.ExportPolicy(
            MetadataExporter exporter,
            PolicyConversionContext context)
        {
            var token            = GetTransportTokenAssertion();
            var transportBinding = TransportBindingElement.CreateTransportBinding(token);

            context.GetBindingAssertions().Add(transportBinding);
        }
        private static void CreateLegacyTransportBindingElement(WsdlImporter importer, SoapBinding soapBinding, WsdlEndpointConversionContext context)
        {
            TransportBindingElement item = CreateTransportBindingElements(soapBinding.Transport, null);

            if (item != null)
            {
                ConvertToCustomBinding(context).Elements.Add(item);
                StateHelper.RegisterTransportBindingElement(importer, context);
            }
        }
        static void CreateLegacyTransportBindingElement(WsdlImporter importer, WsdlNS.SoapBinding soapBinding, WsdlEndpointConversionContext context)
        {
            // We create a transportBindingElement based on the SoapBinding's Transport
            TransportBindingElement transportBindingElement = CreateTransportBindingElements(soapBinding.Transport, null);

            if (transportBindingElement != null)
            {
                ConvertToCustomBinding(context).Elements.Add(transportBindingElement);
                StateHelper.RegisterTransportBindingElement(importer, context);
            }
        }
 private void AddDemuxerBindingElement(BindingElementCollection elements)
 {
     if (elements.Find <ChannelDemuxerBindingElement>() == null)
     {
         TransportBindingElement item = elements.Find <TransportBindingElement>();
         if (item == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("TransportBindingElementNotFound")));
         }
         elements.Insert(elements.IndexOf(item), new ChannelDemuxerBindingElement(true));
     }
 }
Example #19
0
        private void SetMaxReceivedMessageSizeFromTransport(BindingContext context)
        {
            TransportBindingElement transport = context.Binding.Elements.Find <TransportBindingElement>();

            if (transport != null)
            {
                // We are guaranteed that a transport exists when building a binding;
                // Allow the regular flow/checks to happen rather than throw here
                // (InternalBuildChannelListener will call into the BindingContext. Validation happens there and it will throw)
                _maxReceivedMessageSize = transport.MaxReceivedMessageSize;
            }
        }
Example #20
0
 void AddDemuxerBindingElement(BindingElementCollection elements)
 {
     if (elements.Find <ChannelDemuxerBindingElement>() == null)
     {
         // add the channel demuxer binding element right above the transport
         TransportBindingElement transport = elements.Find <TransportBindingElement>();
         if (transport == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TransportBindingElementNotFound)));
         }
         // cache the context state in the demuxer so that the same context state can be provided to the transport
         // when building auxilliary channels and listeners (for ex, for security negotiation)
         elements.Insert(elements.IndexOf(transport), new ChannelDemuxerBindingElement(true));
     }
 }
        private static void ImportAddress(WsdlEndpointConversionContext context, TransportBindingElement transportBindingElement)
        {
            EndpointAddress address = context.Endpoint.Address = WsdlImporter.WSAddressingHelper.ImportAddress(context.WsdlPort);

            if (address != null)
            {
                context.Endpoint.Address = address;
                if ((address.Uri.Scheme == Uri.UriSchemeHttps) && !(transportBindingElement is HttpsTransportBindingElement))
                {
                    BindingElementCollection elements = ConvertToCustomBinding(context).Elements;
                    elements.Remove(transportBindingElement);
                    elements.Add(CreateHttpsFromHttp(transportBindingElement as HttpTransportBindingElement));
                }
            }
        }
Example #22
0
 void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext endpointContext)
 {
     if (endpointContext == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext");
     }
     if (endpointContext.Endpoint.Binding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointContext.Binding");
     }
     if (endpointContext.Endpoint.Binding is CustomBinding)
     {
         System.ServiceModel.Channels.Binding binding;
         BindingElementCollection             elements = ((CustomBinding)endpointContext.Endpoint.Binding).Elements;
         TransportBindingElement element = elements.Find <TransportBindingElement>();
         if (element is HttpTransportBindingElement)
         {
             if (WSHttpBindingBase.TryCreate(elements, out binding))
             {
                 this.SetBinding(endpointContext.Endpoint, binding);
             }
             else if (WSDualHttpBinding.TryCreate(elements, out binding))
             {
                 this.SetBinding(endpointContext.Endpoint, binding);
             }
             else if (BasicHttpBinding.TryCreate(elements, out binding))
             {
                 this.SetBinding(endpointContext.Endpoint, binding);
             }
         }
         else if ((element is MsmqTransportBindingElement) && NetMsmqBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
         else if ((element is NamedPipeTransportBindingElement) && NetNamedPipeBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
         else if ((element is PeerTransportBindingElement) && NetPeerTcpBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
         else if ((element is TcpTransportBindingElement) && NetTcpBinding.TryCreate(elements, out binding))
         {
             this.SetBinding(endpointContext.Endpoint, binding);
         }
     }
 }
Example #23
0
 private CustomBinding(IEnumerable <BindingElement> binding,
                       string name, string ns)
     : base(name, ns)
 {
     elements = new BindingElementCollection(binding);
     foreach (BindingElement be in elements)
     {
         TransportBindingElement tbe = be as TransportBindingElement;
         if (tbe == null)
         {
             continue;
         }
         scheme = tbe.Scheme;
         break;
     }
 }
        private static TransportBindingElement CreateTransportBindingElements(string transportUri, PolicyConversionContext policyContext)
        {
            TransportBindingElement element = null;
            string str = transportUri;

            if (str != null)
            {
                if (!(str == "http://schemas.xmlsoap.org/soap/http"))
                {
                    if (str == "http://schemas.microsoft.com/soap/tcp")
                    {
                        return(new TcpTransportBindingElement());
                    }
                    if (str == "http://schemas.microsoft.com/soap/named-pipe")
                    {
                        return(new NamedPipeTransportBindingElement());
                    }
                    if (str == "http://schemas.microsoft.com/soap/msmq")
                    {
                        return(new MsmqTransportBindingElement());
                    }
                    if (str != "http://schemas.microsoft.com/soap/peer")
                    {
                        return(element);
                    }
                    return(new PeerTransportBindingElement());
                }
                if (policyContext != null)
                {
                    WSSecurityPolicy         securityPolicy    = null;
                    ICollection <XmlElement> bindingAssertions = policyContext.GetBindingAssertions();
                    if (WSSecurityPolicy.TryGetSecurityPolicyDriver(bindingAssertions, out securityPolicy) && securityPolicy.ContainsWsspHttpsTokenAssertion(bindingAssertions))
                    {
                        HttpsTransportBindingElement element2 = new HttpsTransportBindingElement {
                            MessageSecurityVersion = securityPolicy.GetSupportedMessageSecurityVersion(SecurityVersion.WSSecurity11)
                        };
                        element = element2;
                    }
                }
                if (element == null)
                {
                    element = new HttpTransportBindingElement();
                }
            }
            return(element);
        }
        static void ImportAddress(WsdlEndpointConversionContext context, TransportBindingElement transportBindingElement)
        {
            EndpointAddress address = context.Endpoint.Address = WsdlImporter.WSAddressingHelper.ImportAddress(context.WsdlPort);

            if (address != null)
            {
                context.Endpoint.Address = address;

                // Replace the http BE with https BE only if the uri scheme is https and the transport binding element is a HttpTransportBindingElement but not HttpsTransportBindingElement
                if (address.Uri.Scheme == Uri.UriSchemeHttps && transportBindingElement is HttpTransportBindingElement && !(transportBindingElement is HttpsTransportBindingElement))
                {
                    BindingElementCollection elements = ConvertToCustomBinding(context).Elements;
                    elements.Remove(transportBindingElement);
                    elements.Add(CreateHttpsFromHttp(transportBindingElement as HttpTransportBindingElement));
                }
            }
        }
Example #26
0
        internal void EnsureInvariants(string contractName)
        {
            BindingElementCollection elements  = this.CreateBindingElements();
            TransportBindingElement  transport = null;
            int index;

            for (index = 0; index < elements.Count; index++)
            {
                transport = elements[index] as TransportBindingElement;
                if (transport != null)
                {
                    break;
                }
            }

            if (transport == null)
            {
                if (contractName == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.Format(SR.CustomBindingRequiresTransport, this.Name)));
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.Format(SR.SFxCustomBindingNeedsTransport1, contractName)));
                }
            }
            if (index != elements.Count - 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.TransportBindingElementMustBeLast, this.Name, transport.GetType().Name)));
            }
            if (string.IsNullOrEmpty(transport.Scheme))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.InvalidBindingScheme, transport.GetType().Name)));
            }

            if (this.MessageVersion == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.MessageVersionMissingFromBinding, this.Name)));
            }
        }
        static TransportBindingElement CreateTransportBindingElements(string transportUri, PolicyConversionContext policyContext)
        {
            TransportBindingElement transportBindingElement = null;

            // Try and Create TransportBindingElement
            switch (transportUri)
            {
            case TransportPolicyConstants.HttpTransportUri:
                transportBindingElement = GetHttpTransportBindingElement(policyContext);
                break;

            case TransportPolicyConstants.TcpTransportUri:
                transportBindingElement = new TcpTransportBindingElement();
                break;

            case TransportPolicyConstants.NamedPipeTransportUri:
                transportBindingElement = new NamedPipeTransportBindingElement();
                break;

            case TransportPolicyConstants.MsmqTransportUri:
                transportBindingElement = new MsmqTransportBindingElement();
                break;

            case TransportPolicyConstants.PeerTransportUri:
#pragma warning disable 0618
                transportBindingElement = new PeerTransportBindingElement();
#pragma warning restore 0618
                break;

            case TransportPolicyConstants.WebSocketTransportUri:
                HttpTransportBindingElement httpTransport = GetHttpTransportBindingElement(policyContext);
                httpTransport.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
                httpTransport.WebSocketSettings.SubProtocol    = WebSocketTransportSettings.SoapSubProtocol;
                transportBindingElement = httpTransport;
                break;

            default:
                // There may be another registered converter that can handle this transport.
                break;
            }

            return(transportBindingElement);
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            XmlQualifiedName name;
            string           transportUri = WsdlImporter.SoapInPolicyWorkaroundHelper.FindAdHocTransportPolicy(policyContext, out name);

            if ((transportUri != null) && !policyContext.BindingElements.Contains(typeof(TransportBindingElement)))
            {
                TransportBindingElement item = CreateTransportBindingElements(transportUri, policyContext);
                if (item != null)
                {
                    ITransportPolicyImport import = item as ITransportPolicyImport;
                    if (import != null)
                    {
                        import.ImportPolicy(importer, policyContext);
                    }
                    policyContext.BindingElements.Add(item);
                    StateHelper.RegisterTransportBindingElement(importer, name);
                }
            }
        }
Example #29
0
        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext)
        {
            bool createdNew;
            MessageEncodingBindingElement encodingBindingElement = FindMessageEncodingBindingElement(endpointContext, out createdNew);
            bool useWebSocketTransport = WebSocketHelper.UseWebSocketTransport(this.WebSocketSettings.TransportUsage, endpointContext.ContractConversionContext.Contract.IsDuplex());

            EndpointAddress address = endpointContext.Endpoint.Address;

            if (useWebSocketTransport)
            {
                address = new EndpointAddress(WebSocketHelper.GetWebSocketUri(endpointContext.Endpoint.Address.Uri), endpointContext.Endpoint.Address);
                WsdlNS.SoapAddressBinding binding = SoapHelper.GetSoapAddressBinding(endpointContext.WsdlPort);
                if (binding != null)
                {
                    binding.Location = address.Uri.AbsoluteUri;
                }
            }

            TransportBindingElement.ExportWsdlEndpoint(exporter, endpointContext,
                                                       this.GetWsdlTransportUri(useWebSocketTransport), address, encodingBindingElement.MessageVersion.Addressing);
        }
Example #30
0
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw FxTrace.Exception.ArgumentNull("context");
            }

            if (context.Endpoint.Binding == null)
            {
                throw FxTrace.Exception.ArgumentNull("context.Endpoint.Binding");
            }

            BindingElementCollection bindingElements         = context.Endpoint.Binding.CreateBindingElements();
            TransportBindingElement  transportBindingElement = bindingElements.Find <TransportBindingElement>();

            if (transportBindingElement is UdpTransportBindingElement)
            {
                ImportEndpointAddress(context);
            }

            if (context.Endpoint.Binding is CustomBinding)
            {
                Binding newEndpointBinding = null;
                if (transportBindingElement is UdpTransportBindingElement)
                {
                    Binding udpBinding;
                    if (UdpBinding.TryCreate(bindingElements, out udpBinding))
                    {
                        newEndpointBinding = udpBinding;
                    }

                    if (newEndpointBinding != null)
                    {
                        newEndpointBinding.Name      = context.Endpoint.Binding.Name;
                        newEndpointBinding.Namespace = context.Endpoint.Binding.Namespace;
                        context.Endpoint.Binding     = newEndpointBinding;
                    }
                }
            }
        }