public static void LeaseTimeout_Property_Set_Invalid_Value_Throws(TimeSpan timeSpan)
 {
     // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement
     TcpTransportBindingElement element = new TcpTransportBindingElement();
     TcpConnectionPoolSettings settings = element.ConnectionPoolSettings;
     Assert.Throws<ArgumentOutOfRangeException>(() => settings.LeaseTimeout = timeSpan);
 }
 private static CustomBinding CreateTcpBinding()
 {
     CustomBinding binding = new CustomBinding("MetadataExchangeTcpBinding", "http://schemas.microsoft.com/ws/2005/02/mex/bindings", new BindingElement[0]);
     TcpTransportBindingElement item = new TcpTransportBindingElement();
     binding.Elements.Add(item);
     return binding;
 }
 private void CreateBinding()
 {
     Collection<BindingElement> bindingElementsInTopDownChannelStackOrder = new Collection<BindingElement>();
     BindingElement securityBindingElement = this.config.SecurityManager.GetSecurityBindingElement();
     if (securityBindingElement != null)
     {
         bindingElementsInTopDownChannelStackOrder.Add(securityBindingElement);
     }
     TcpTransportBindingElement item = new TcpTransportBindingElement {
         MaxReceivedMessageSize = this.config.MaxReceivedMessageSize,
         MaxBufferPoolSize = this.config.MaxBufferPoolSize,
         TeredoEnabled = true
     };
     MessageEncodingBindingElement encodingBindingElement = null;
     if (this.messageHandler != null)
     {
         encodingBindingElement = this.messageHandler.EncodingBindingElement;
     }
     if (encodingBindingElement == null)
     {
         BinaryMessageEncodingBindingElement element4 = new BinaryMessageEncodingBindingElement();
         this.config.ReaderQuotas.CopyTo(element4.ReaderQuotas);
         bindingElementsInTopDownChannelStackOrder.Add(element4);
     }
     else
     {
         bindingElementsInTopDownChannelStackOrder.Add(encodingBindingElement);
     }
     bindingElementsInTopDownChannelStackOrder.Add(item);
     this.binding = new CustomBinding(bindingElementsInTopDownChannelStackOrder);
     this.binding.ReceiveTimeout = TimeSpan.MaxValue;
 }
 NetTcpBinding(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context, ReliableSessionBindingElement session, NetTcpSecurity security)
     : this()
 {
     this.security = security;
     this.ReliableSession.Enabled = session != null;
     InitializeFrom(transport, encoding, context, session);
 }
Example #5
0
 private NetTcpBinding(TcpTransportBindingElement transport,
               BinaryMessageEncodingBindingElement encoding,
               NetTcpSecurity security)
     : this()
 {
     _security = security;
 }
		internal NetTcpBinding (TcpTransportBindingElement transport,
		                        NetTcpSecurity security,
		                        bool reliableSessionEnabled)
		{
			this.transport = transport;
			this.security = security;
		}
 public static void GroupName_Property_Set_Null_Value_Throws()
 {
     // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement
     TcpTransportBindingElement element = new TcpTransportBindingElement();
     TcpConnectionPoolSettings settings = element.ConnectionPoolSettings;
     Assert.Throws<ArgumentNullException>(() => settings.GroupName = null);
 }
 public static void MaxOutboundConnectionsPerEndpoint_Property_Sets(int value)
 {
     // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement
     TcpTransportBindingElement element = new TcpTransportBindingElement();
     TcpConnectionPoolSettings settings = element.ConnectionPoolSettings;
     settings.MaxOutboundConnectionsPerEndpoint = value;
     Assert.Equal<int>(value, settings.MaxOutboundConnectionsPerEndpoint);
 }
 public static void GroupName_Property_Sets(string groupName)
 {
     // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement
     TcpTransportBindingElement element = new TcpTransportBindingElement();
     TcpConnectionPoolSettings settings = element.ConnectionPoolSettings;
     settings.GroupName = groupName;
     Assert.Equal<string>(groupName, settings.GroupName);
 }
 public static void LeaseTimeout_Property_Sets(TimeSpan timeSpan)
 {
     // TcpConnectionPoolSettings has no public constructor but we can access it from the TcpTransportBindingElement
     TcpTransportBindingElement element = new TcpTransportBindingElement();
     TcpConnectionPoolSettings settings = element.ConnectionPoolSettings;
     settings.LeaseTimeout = timeSpan;
     Assert.Equal<TimeSpan>(timeSpan, settings.LeaseTimeout);
 }
 void Initialize()
 {
     be = new ChunkingBindingElement();
      tcpbe = new TcpTransportBindingElement();
      tcpbe.TransferMode=TransferMode.Buffered; //no transport streaming
      tcpbe.MaxReceivedMessageSize = ChunkingUtils.ChunkSize + 100 * 1024; //add 100KB for headers
      this.SendTimeout = new TimeSpan(0, 5, 0);
      this.ReceiveTimeout = this.SendTimeout;
 }
Example #12
0
    public static void Ctor_Default_Properties()
    {
        // Validates new TcpTransportBindingElement() initializes correct default property values
        TcpTransportBindingElement element = new TcpTransportBindingElement();

        Assert.True(String.Equals(element.Scheme, "net.tcp"), String.Format("Scheme property expected '{0}' but actual was '{1}'", "net.tcp", element.Scheme));

        // Validate only a non-null TcpConnectionPoolSetting.
        // Its own default values are validated in that type's test methods
        Assert.True(element.ConnectionPoolSettings != null, "ConnectionPoolSettings should not be null.");
    }
 /// <summary>
 /// Initializes the binding.
 /// </summary>
 /// <param name="namespaceUris">The namespace uris.</param>
 /// <param name="factory">The factory.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="descriptions">The descriptions.</param>
 public UaTcpBinding(
     NamespaceTable               namespaceUris,
     EncodeableFactory            factory,
     EndpointConfiguration        configuration,
     params EndpointDescription[] descriptions)
 :
     base(namespaceUris, factory, configuration)
 {
     m_transport = new TcpTransportBindingElement();
     m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize;
 }
Example #14
0
		private static void AddMexEndpointMetadata(ServiceHost host)
		{
			var tcpBinding = new TcpTransportBindingElement();
			var customBinding = new CustomBinding(tcpBinding);

			// validate whether ServiceMetadataBehavior is present
			var metaDataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
			if (metaDataBehavior == null)
			{
				metaDataBehavior = new ServiceMetadataBehavior();
				host.Description.Behaviors.Add(metaDataBehavior);
			}
			host.AddServiceEndpoint(typeof(IMetadataExchange), customBinding, "MEX");
		}
Example #15
0
		public static ServiceEndpoint[] GetEndpoints(string mexAddress)
		{
			var address = new Uri(mexAddress);
			ServiceEndpointCollection endpoints = null;

			if (address.Scheme == "net.tcp")
			{
				var tcpBindingElement = new TcpTransportBindingElement();
				tcpBindingElement.MaxReceivedMessageSize *= MessageMultiplier;
				endpoints = QueryMexEndpoint(mexAddress, tcpBindingElement);
			}
			if (address.Scheme == "net.pipe") { }
			if (address.Scheme == "http") { }
			if (address.Scheme == "https") { }

			return endpoints.ToArray();
		}
        public FileDownloadService()
        {
            TcpTransportBindingElement transport = new TcpTransportBindingElement();
            transport.MaxReceivedMessageSize = long.MaxValue;
            transport.MaxBufferSize = int.MaxValue;
            transport.MaxBufferPoolSize = long.MaxValue;
            transport.TransferMode = TransferMode.Streamed;

            BinaryMessageEncodingBindingElement encoder = new BinaryMessageEncodingBindingElement();
            CustomBinding binding = new CustomBinding(encoder, transport);
            binding.ReceiveTimeout = TimeSpan.MaxValue;
            binding.SendTimeout = TimeSpan.MaxValue;
            binding.CloseTimeout = TimeSpan.MaxValue;

            serviceHost = new ServiceHost(this);
            serviceHost.AddServiceEndpoint(typeof(IFileDownloadService), binding, "net.tcp://localhost:8020");
            serviceHost.Open();
        }
        public static void SetBindingProperties(this Binding binding, ServiceConfig bindingProperties)
        {
            if (binding.GetType().Equals(typeof(System.ServiceModel.NetTcpBinding)))
            {
                //(binding as System.ServiceModel.NetTcpBinding).Security.Message.ClientCredentialType = bindingProperties.MessageCredentialType;
                //(binding as System.ServiceModel.NetTcpBinding).Security.Transport.ClientCredentialType = bindingProperties.TcpClientCredentialType;
                //(binding as System.ServiceModel.NetTcpBinding).Security.Transport.ProtectionLevel = bindingProperties.ProtectionLevel;

                (binding as System.ServiceModel.NetTcpBinding).MaxConnections = bindingProperties.NetParameter.MaxConnections;

                (binding as System.ServiceModel.NetTcpBinding).MaxReceivedMessageSize = bindingProperties.NetParameter.MaxReceivedMessageSize;
                (binding as System.ServiceModel.NetTcpBinding).MaxBufferPoolSize = bindingProperties.NetParameter.MaxBufferPoolSize;

                (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxArrayLength = bindingProperties.NetParameter.MaxArrayLength;
                (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxBytesPerRead = bindingProperties.NetParameter.MaxBytesPerRead;
                (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxDepth = bindingProperties.NetParameter.MaxDepth;
                (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxStringContentLength = bindingProperties.NetParameter.MaxStringContentLength;
                (binding as System.ServiceModel.NetTcpBinding).ReaderQuotas.MaxNameTableCharCount = bindingProperties.NetParameter.MaxNameTableCharCount;
            }
            //not allowed by partially trusted
            //tcpBinding.MaxBufferSize = 262144;							//256KB default is 65,536 bytes

            binding.OpenTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.OpenTimeout);
            binding.CloseTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.CloseTimeout);
            binding.ReceiveTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.ReceiveTimeout);
            binding.SendTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.SendTimeout);

            CustomBinding cb = new CustomBinding(binding);

            TcpTransportBindingElement tcpe = new TcpTransportBindingElement();
            tcpe.ConnectionBufferSize = bindingProperties.NetParameter.ConnectionBufferSize;
            tcpe.ConnectionPoolSettings.LeaseTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.ConnectionLeaseTimeout);
            tcpe.ConnectionPoolSettings.IdleTimeout = TimeSpan.FromSeconds(bindingProperties.NetParameter.IdleTimeout);
            tcpe.ListenBacklog = bindingProperties.NetParameter.ListenBacklog;
            tcpe.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = bindingProperties.NetParameter.MaxOutboundConnectionsPerEndpoint;
            tcpe.MaxOutputDelay = TimeSpan.FromSeconds(bindingProperties.NetParameter.MaxOutputDelay);
            tcpe.MaxPendingAccepts = bindingProperties.NetParameter.MaxPendingAccepts;
            tcpe.MaxPendingConnections = bindingProperties.NetParameter.MaxPendingConnections;

            cb.Elements.Add(tcpe);

            binding = cb;
        }
Example #18
0
	public static void Main ()
	{
Console.WriteLine ("WARNING!! This test is not configured enought to work fine on .NET either.");

		SymmetricSecurityBindingElement sbe =
			new SymmetricSecurityBindingElement ();
		sbe.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
		sbe.RequireSignatureConfirmation = true;
		//sbe.IncludeTimestamp = false;

		sbe.ProtectionTokenParameters =
			new X509SecurityTokenParameters (X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
		X509SecurityTokenParameters p =
			new X509SecurityTokenParameters (X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.AlwaysToRecipient);
		p.RequireDerivedKeys = false;
		sbe.EndpointSupportingTokenParameters.Endorsing.Add (p);
		//sbe.SetKeyDerivation (false);
		//sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
		ServiceHost host = new ServiceHost (typeof (Foo));
		var mbe = new BinaryMessageEncodingBindingElement ();
		var tbe = new TcpTransportBindingElement ();
		CustomBinding binding = new CustomBinding (sbe, mbe, tbe);
		binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
		host.AddServiceEndpoint ("IFoo",
			binding, new Uri ("http://localhost:8080"));
		ServiceCredentials cred = new ServiceCredentials ();
		cred.ServiceCertificate.Certificate =
			new X509Certificate2 ("test.pfx", "mono");
		cred.ClientCertificate.Authentication.CertificateValidationMode =
			X509CertificateValidationMode.None;
		host.Description.Behaviors.Add (cred);
		host.Description.Behaviors.Find<ServiceDebugBehavior> ()
			.IncludeExceptionDetailInFaults = true;
		ServiceMetadataBehavior smb = new ServiceMetadataBehavior ();
		smb.HttpGetEnabled = true;
		smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl");
		host.Description.Behaviors.Add (smb);
		host.Open ();
		Console.WriteLine ("Hit [CR] key to close ...");
		Console.ReadLine ();
		host.Close ();
	}
        /// <summary>
        /// Initializes the binding.
        /// </summary>
        /// <param name="namespaceUris">The namespace uris.</param>
        /// <param name="factory">The factory.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="description">The description.</param>
        public UaSoapXmlOverTcpBinding(
            NamespaceTable        namespaceUris,
            EncodeableFactory     factory,
            EndpointConfiguration configuration,
            EndpointDescription   description)
        :
            base(namespaceUris, factory, configuration)
        {                   
            if (description != null && description.SecurityMode != MessageSecurityMode.None)
            {
                TransportSecurityBindingElement bootstrap = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
                bootstrap.IncludeTimestamp             = true;
                bootstrap.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                bootstrap.SecurityHeaderLayout         = SecurityHeaderLayout.Strict;
                
                m_security = SecurityBindingElement.CreateSecureConversationBindingElement(bootstrap);
                m_security.IncludeTimestamp             = true;
                m_security.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                m_security.SecurityHeaderLayout         = SecurityHeaderLayout.Strict;
            }
            
            m_encoding = new BinaryMessageEncodingBindingElement();
           
            // WCF does not distinguish between arrays and byte string.
            int maxArrayLength = configuration.MaxArrayLength;

            if (configuration.MaxArrayLength < configuration.MaxByteStringLength)
            {
                maxArrayLength = configuration.MaxByteStringLength;
            }

            m_encoding.ReaderQuotas.MaxArrayLength         = maxArrayLength;
            m_encoding.ReaderQuotas.MaxStringContentLength = configuration.MaxStringLength;
            m_encoding.ReaderQuotas.MaxBytesPerRead        = Int32.MaxValue;
            m_encoding.ReaderQuotas.MaxDepth               = Int32.MaxValue;
            m_encoding.ReaderQuotas.MaxNameTableCharCount  = Int32.MaxValue;

            m_transport = new TcpTransportBindingElement();

            m_transport.ManualAddressing       = false;
            m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize;
        }
Example #20
0
 static void Main(string[] args)
 {
     NetTcpBinding bind = new NetTcpBinding();
     Uri uri = new Uri(ConfigurationManager.AppSettings["conAddress"]);//从配置文件中读取服务的Url
     ServiceHost host = new ServiceHost(typeof(WCFChatService.ChatService), uri);
     //if中的代码可以没有,但是如果想利用Svctuil.exe生成代理类的时候,就需要下面的代码,否则将会报错,无法解析元数据
     if (host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
     {
         BindingElement metaElement = new TcpTransportBindingElement();
         CustomBinding metaBind = new CustomBinding(metaElement);
         host.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior());
         host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), metaBind, "MEX");
     }
     host.Open();        
     Console.WriteLine("聊天室服务器开始监听: endpoint {0}", uri.ToString());
     Console.WriteLine("按 ENTER 停止服务器监听...");
     Console.ReadLine();
     host.Abort();
     host.Close(); 
 }
		public void CanBuildChannelFactory ()
		{
			TcpTransportBindingElement be =
				new TcpTransportBindingElement ();
			BindingContext ctx = new BindingContext (
				new CustomBinding (), empty_params);
			Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
			Assert.IsFalse (be.CanBuildChannelFactory<IInputChannel> (ctx), "#2");
			Assert.IsFalse (be.CanBuildChannelFactory<IReplyChannel> (ctx), "#3");
			Assert.IsFalse (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#4");

			Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#5");
			Assert.IsFalse (be.CanBuildChannelFactory<IInputSessionChannel> (ctx), "#6");
			Assert.IsFalse (be.CanBuildChannelFactory<IReplySessionChannel> (ctx), "#7");
			Assert.IsFalse (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#8");

			// IServiceChannel is not supported
			Assert.IsFalse (be.CanBuildChannelFactory<IServiceChannel> (ctx), "#9");
			Assert.IsFalse (be.CanBuildChannelFactory<IClientChannel> (ctx), "#10");

			Assert.IsFalse (be.CanBuildChannelFactory<IDuplexChannel> (ctx), "#11");
			Assert.IsTrue (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#12");
		}
Example #22
0
    public static void SameBinding_SecurityModeNone_Text_EchoString_Roundtrip()
    {
        BindingElement[] bindingElements = null;
        CustomBinding binding = null;
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;
        EndpointAddress endpointAddress = null;
        string result = null;
        string testString = "Hello";

        try
        {
            // *** SETUP *** \\
            bindingElements = new BindingElement[2];
            bindingElements[0] = new TextMessageEncodingBindingElement();
            bindingElements[1] = new TcpTransportBindingElement();
            binding = new CustomBinding(bindingElements);
            endpointAddress = new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address);
            factory = new ChannelFactory<IWcfService>(binding, endpointAddress);
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.True(String.Equals(result, testString), String.Format("    Error: expected response from service: '{0}' Actual was: '{1}'", testString, result));

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
		public void DefaultValues ()
		{
			TcpTransportBindingElement be =
				new TcpTransportBindingElement ();
			Assert.AreEqual (TimeSpan.FromSeconds (5), be.ChannelInitializationTimeout, "#1");
			Assert.AreEqual (0x2000, be.ConnectionBufferSize, "#2");
			Assert.AreEqual (HostNameComparisonMode.StrongWildcard, be.HostNameComparisonMode, "#3");
			Assert.AreEqual (0x10000, be.MaxBufferSize, "#4");
			Assert.AreEqual (TimeSpan.FromMilliseconds (200), be.MaxOutputDelay, "#5");
			Assert.AreEqual (1, be.MaxPendingAccepts, "#6");
			Assert.AreEqual (10, be.MaxPendingConnections, "#7");
			Assert.AreEqual (TransferMode.Buffered, be.TransferMode, "#8");

			Assert.AreEqual (10, be.ListenBacklog, "#9");
			Assert.IsFalse (be.PortSharingEnabled, "#10");
			Assert.AreEqual ("net.tcp", be.Scheme, "#11");
			Assert.IsFalse (be.TeredoEnabled, "#12");
			TcpConnectionPoolSettings pool = be.ConnectionPoolSettings;
			Assert.IsNotNull (pool, "#13");
			Assert.AreEqual ("default", pool.GroupName, "#14");
			Assert.AreEqual (TimeSpan.FromSeconds (120), pool.IdleTimeout, "#15");
			Assert.AreEqual (TimeSpan.FromSeconds (300), pool.LeaseTimeout, "#16");
			Assert.AreEqual (10, pool.MaxOutboundConnectionsPerEndpoint, "#17");
		}
Example #24
0
    public static void SameBinding_SecurityModeNone_Text_EchoString_Roundtrip()
    {
        string variationDetails = "Client:: CustomBinding/TcpTransport/NoWindowsStreamSecurity/TextMessageEncoding = None\nServer:: CustomBinding/TcpTransport/NoWindowsStreamSecurity/TextMessageEncoding = None";
        string testString = "Hello";
        StringBuilder errorBuilder = new StringBuilder();
        bool success = false;

        try
        {
            BindingElement[] bindingElements = new BindingElement[2];
            bindingElements[0] = new TextMessageEncodingBindingElement();
            bindingElements[1] = new TcpTransportBindingElement();
            CustomBinding binding = new CustomBinding(bindingElements);

            ChannelFactory<IWcfService> factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.Tcp_CustomBinding_NoSecurity_Text_Address));
            IWcfService serviceProxy = factory.CreateChannel();

            string result = serviceProxy.Echo(testString);
            success = string.Equals(result, testString);

            if (!success)
            {
                errorBuilder.AppendLine(String.Format("    Error: expected response from service: '{0}' Actual was: '{1}'", testString, result));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("    Error: Unexpected exception was caught while doing the basic echo test for variation...\n'{0}'\nException: {1}", variationDetails, ex.ToString()));
            for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException)
            {
                errorBuilder.AppendLine(String.Format("Inner exception: {0}", innerException.ToString()));
            }
        }

        Assert.True(errorBuilder.Length == 0, "Test case FAILED with errors: " + errorBuilder.ToString());
    }
 public static ServiceEndpointCollection GetEndpoints(string mexAddress)
 {
     Uri mexUri = new Uri(mexAddress);
     TransportBindingElement transportElement;
     switch (mexUri.Scheme)
     {
         case "net.tcp":
             transportElement = new TcpTransportBindingElement();
             break;
         case "net.pipe":
             transportElement = new NamedPipeTransportBindingElement();
             break;
         case "http":
             transportElement = new HttpTransportBindingElement();
             break;
         case "https":
             transportElement = new HttpsTransportBindingElement();
             break;
         default:
             throw new NotSupportedException("Scheme not supported.");
     }
     transportElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
     return GetEndpoints(mexUri, transportElement); ;
 }
Example #26
0
        public static ServiceEndpoint[] GetEndpoints(string mexAddress)
        {
            if (String.IsNullOrEmpty(mexAddress))
            {
                Debug.Assert(false, "Empty address");
                return null;
            }
            Uri address = new Uri(mexAddress);
            ServiceEndpointCollection endpoints = null;

            if (address.Scheme == "http")
            {
                HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
                httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;

                //Try the HTTP MEX Endpoint
                try
                {
                    endpoints = QueryMexEndpoint(mexAddress, httpBindingElement);
                }
                catch
                { }

                //Try over HTTP-GET
                if (endpoints == null)
                {
                    string httpGetAddress = mexAddress;
                    if (mexAddress.EndsWith("?wsdl") == false)
                    {
                        httpGetAddress += "?wsdl";
                    }
                    CustomBinding binding = new CustomBinding(httpBindingElement);
                    MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
                    MetadataSet metadata = mexClient.GetMetadata(new Uri(httpGetAddress), MetadataExchangeClientMode.HttpGet);
                    MetadataImporter importer = new WsdlImporter(metadata);
                    endpoints = importer.ImportAllEndpoints();
                }
            }
            if (address.Scheme == "https")
            {
                HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement();
                httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;

                //Try the HTTPS MEX Endpoint
                try
                {
                    endpoints = QueryMexEndpoint(mexAddress, httpsBindingElement);
                }
                catch
                { }

                //Try over HTTPS-GET
                if (endpoints == null)
                {
                    string httpsGetAddress = mexAddress;
                    if (mexAddress.EndsWith("?wsdl") == false)
                    {
                        httpsGetAddress += "?wsdl";
                    }
                    CustomBinding binding = new CustomBinding(httpsBindingElement);
                    MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
                    MetadataSet metadata = mexClient.GetMetadata(new Uri(httpsGetAddress), MetadataExchangeClientMode.HttpGet);
                    MetadataImporter importer = new WsdlImporter(metadata);
                    endpoints = importer.ImportAllEndpoints();
                }
            }
            if (address.Scheme == "net.tcp")
            {
                TcpTransportBindingElement tcpBindingElement = new TcpTransportBindingElement();
                tcpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
                endpoints = QueryMexEndpoint(mexAddress, tcpBindingElement);
            }
            if (address.Scheme == "net.pipe")
            {
                NamedPipeTransportBindingElement ipcBindingElement = new NamedPipeTransportBindingElement();
                ipcBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
                endpoints = QueryMexEndpoint(mexAddress, ipcBindingElement);
            }
            return endpoints.ToArray();
        }
Example #27
0
        public static ServiceEndpoint[] GetEndpoints(string mexAddress)
        {
            if(string.IsNullOrWhiteSpace(mexAddress))
             {
            throw new ArgumentException("mexAddress");
             }

             Uri address = new Uri(mexAddress);
             ServiceEndpointCollection endpoints = null;
             BindingElement bindingElement = null;

             //Try over HTTP-GET first
             if(address.Scheme == Uri.UriSchemeHttp || address.Scheme == Uri.UriSchemeHttps)
             {
            string getAddress = mexAddress;
            if(mexAddress.EndsWith("?wsdl") == false)
            {
               getAddress += "?wsdl";
            }
            if(address.Scheme == Uri.UriSchemeHttp)
            {
               HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
               httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
               bindingElement = httpBindingElement;
            }
            else
            {
               HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement();
               httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
               bindingElement = httpsBindingElement;
            }
            CustomBinding binding = new CustomBinding(bindingElement);

            MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
            MetadataSet metadata = mexClient.GetMetadata(new Uri(getAddress),MetadataExchangeClientMode.HttpGet);
            MetadataImporter importer = new WsdlImporter(metadata);
            endpoints = importer.ImportAllEndpoints();
            return endpoints.ToArray();
             }

             //Try MEX endpoint:

             if(address.Scheme == Uri.UriSchemeHttp)
             {
            bindingElement = new HttpTransportBindingElement();
             }
             if(address.Scheme == Uri.UriSchemeHttps)
             {
            bindingElement = new HttpsTransportBindingElement();
             }
             if(address.Scheme == Uri.UriSchemeNetTcp)
             {
            bindingElement = new TcpTransportBindingElement();
             }
             if(address.Scheme == Uri.UriSchemeNetPipe)
             {
            bindingElement = new NamedPipeTransportBindingElement();
             }

             endpoints = QueryMexEndpoint(mexAddress,bindingElement);
             return endpoints.ToArray();
        }
Example #28
0
        // check that properties of the HttpTransportBindingElement and 
        // MessageEncodingBindingElement not exposed as properties on BasicHttpBinding 
        // match default values of the binding elements
        private bool IsBindingElementsMatch(TcpTransportBindingElement transport, BinaryMessageEncodingBindingElement encoding)
        {
            if (!_transport.IsMatch(transport))
                return false;

            if (!_encoding.IsMatch(encoding))
                return false;

            return true;
        }
		public void CanBuildChannelFactory ()
		{
			// with HttpTransport
			var m = new WebMessageEncodingBindingElement ();
			Assert.IsTrue (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#1");
			Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#2");
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#3");
			Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#4");

			// actually they are from transport
			var h = new HttpTransportBindingElement ();
			Assert.IsTrue (h.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#5");
			Assert.IsFalse (h.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#6");
			Assert.IsFalse (h.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#7");
			Assert.IsFalse (h.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#8");

			// with TcpTransport
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#9");
			Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#10");
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#11");
			Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#12");

			// ... yes, actually they are from transport
			var t = new TcpTransportBindingElement ();
			Assert.IsFalse (t.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#13");
			Assert.IsFalse (t.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#14");
			Assert.IsFalse (t.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#15");
			Assert.IsFalse (t.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#16");
		}
Example #30
0
        private void Initialize()
        {
            _transport = new TcpTransportBindingElement();
            _encoding = new BinaryMessageEncodingBindingElement();

            // NetNative and CoreCLR initialize to what TransportBindingElement does in the desktop
            // This property is not available in shipped contracts
            _maxBufferPoolSize = TransportDefaults.MaxBufferPoolSize;
        }