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


C# CustomBinding.BuildChannelFactory方法代码示例

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


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

示例1: ReceiveFactory

        public void ReceiveFactory()
        {
            Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisReceiveTransportBinding());

            IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>();
            Assert.IsInstanceOf<RedisReceiveFactory>(factory);
        }
开发者ID:nnyegaard,项目名称:REWBI,代码行数:7,代码来源:REWBITest.cs

示例2: Main

        static void Main(string[] args)
        {
            try
            {
                BindingElement[] bindingElements = new BindingElement[2];
                bindingElements[0] = new TextMessageEncodingBindingElement();
                bindingElements[1] = new HttpTransportBindingElement();

                CustomBinding binding = new CustomBinding(bindingElements);
                using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body"))
                {
                    IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
                    factory.Open();

                    IRequestChannel requestChannel = factory.CreateChannel(new EndpointAddress("http://localhost:9090/RequestReplyService"));
                    requestChannel.Open();
                    Message response = requestChannel.Request(message);

                    Console.WriteLine("Successful send message!");

                    Console.WriteLine("Receive a return message, action: {0}, body: {1}", response.Headers.Action, response.GetBody<String>());
                    requestChannel.Close();
                    factory.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally {
                Console.Read();
            }
        }
开发者ID:porter1130,项目名称:MyTest,代码行数:33,代码来源:Output.cs

示例3: ConnectAsync

        public async Task<RelayConnection> ConnectAsync()
        {
            var tb = new TransportClientEndpointBehavior(tokenProvider);
            var bindingElement = new TcpRelayTransportBindingElement(
                RelayClientAuthenticationType.RelayAccessToken)
            {
                TransferMode = TransferMode.Buffered,
                ConnectionMode = TcpRelayConnectionMode.Relayed,
                ManualAddressing = true
            };
            bindingElement.GetType()
                .GetProperty("TransportProtectionEnabled",
                    BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic)
                .SetValue(bindingElement, true);

            var rt = new CustomBinding(
                new BinaryMessageEncodingBindingElement(),
                bindingElement);

            var cf = rt.BuildChannelFactory<IDuplexSessionChannel>(tb);
            await Task.Factory.FromAsync(cf.BeginOpen, cf.EndOpen, null);
            var ch = cf.CreateChannel(new EndpointAddress(address));
            await Task.Factory.FromAsync(ch.BeginOpen, ch.EndOpen, null);
            return new RelayConnection(ch)
            {
                WriteTimeout = (int) rt.SendTimeout.TotalMilliseconds,
                ReadTimeout = (int) rt.ReceiveTimeout.TotalMilliseconds
            };
        }
开发者ID:lokeshsp,项目名称:azure-servicebus-relay-samples,代码行数:29,代码来源:RelayClient.cs

示例4: BuildChannelWithoutProtectionTokenParameters

		public void BuildChannelWithoutProtectionTokenParameters ()
		{
			CustomBinding b = new CustomBinding (
				new SymmetricSecurityBindingElement (),
				new TextMessageEncodingBindingElement (),
				new HttpTransportBindingElement ());
			b.BuildChannelFactory<IRequestChannel> (new BindingParameterCollection ());
		}
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:SymmetricSecurityBindingElementTest.cs

示例5: SendChannel

        public void SendChannel()
        {
            Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisSendTransportBinding());
            EndpointAddress address = new EndpointAddress("redis://localhost:6379");

            IChannelFactory<IDuplexChannel> factory = binding.BuildChannelFactory<IDuplexChannel>();
            factory.Open();
            IDuplexChannel duplexChannel = factory.CreateChannel(address);
            Assert.IsInstanceOf<RedisSendChannel>(duplexChannel);
        }
开发者ID:nnyegaard,项目名称:REWBI,代码行数:10,代码来源:REWBITest.cs

示例6: IRequestChannel_Http_CustomBinding

    public static void IRequestChannel_Http_CustomBinding()
    {
        try
        {
            BindingElement[] bindingElements = new BindingElement[2];
            bindingElements[0] = new TextMessageEncodingBindingElement();
            bindingElements[1] = new HttpTransportBindingElement();
            CustomBinding binding = new CustomBinding(bindingElements);

            // Create the channel factory for the request-reply message exchange pattern.
            IChannelFactory<IRequestChannel> factory =
            binding.BuildChannelFactory<IRequestChannel>(
                             new BindingParameterCollection());
            factory.Open();

            // Create the channel.
            IRequestChannel channel = factory.CreateChannel(
               new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
            channel.Open();

            // Create the Message object to send to the service.
            Message requestMessage = Message.CreateMessage(
                binding.MessageVersion,
                action,
                new CustomBodyWriter(clientMessage));

            // Send the Message and receive the Response.
            Message replyMessage = channel.Request(requestMessage);
            string replyMessageAction = replyMessage.Headers.Action;

            if (!string.Equals(replyMessageAction, action + "Response"))
            {
                Assert.True(false, String.Format("A response was received from the Service but it was not the expected Action, expected: {0} actual: {1}", action + "Response", replyMessageAction));
            }


            var replyReader = replyMessage.GetReaderAtBodyContents();
            string actualResponse = replyReader.ReadElementContentAsString();
            string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
            if (!string.Equals(actualResponse, expectedResponse))
            {
                Assert.True(false, String.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse));
            }

            replyMessage.Close();
            channel.Close();
            factory.Close();
        }

        catch (Exception ex)
        {
            Assert.True(false, String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }
    }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:54,代码来源:RequestReplyChannelShapeTests.cs

示例7: ReceiveMessage

        public void ReceiveMessage()
        {
            Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisReceiveTransportBinding());
            EndpointAddress address = new EndpointAddress("redis://localhost:6379");

            IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>();
            factory.Open();
            IRequestChannel channel = factory.CreateChannel(address);
            channel.Open();
            Message requestMessage = Message.CreateMessage(MessageVersion.Default, "http://tempuri", "Key");
            Message replyMessage = channel.Request(requestMessage, TimeSpan.FromSeconds(5));
            StringAssert.Contains("Value",replyMessage.GetBody<string>());
        }
开发者ID:nnyegaard,项目名称:REWBI,代码行数:13,代码来源:REWBITest.cs

示例8: SendData

        private static void SendData()
        {
            Console.WriteLine("Sending data:");
            Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisSendTransportBinding());
            EndpointAddress address = new EndpointAddress("redis://localhost:6379");

            IChannelFactory<IDuplexChannel> factory = binding.BuildChannelFactory<IDuplexChannel>();
            factory.Open();
            IDuplexChannel duplexChannel = factory.CreateChannel(address);
            duplexChannel.Open();

            Message requestMessage = Message.CreateMessage(MessageVersion.Default, "http://tempuri", "Key:Value");

            duplexChannel.Send(requestMessage);
        }
开发者ID:nnyegaard,项目名称:REWBI,代码行数:15,代码来源:Program.cs

示例9: Main

		public static void Main ()
		{
			Console.WriteLine ("Press ENTER when service is ready.");
			Console.ReadLine ();
			
			CustomBinding binding = new CustomBinding ();
			binding.Elements.Add (new TextMessageEncodingBindingElement ());
			binding.Elements.Add (new TcpTransportBindingElement ());
			
			BindingParameterCollection bpcol = 
				new BindingParameterCollection ();
			
//			using (IChannelFactory<IDuplexSessionChannel> factory =
//			binding.BuildChannelFactory<IDuplexSessionChannel>(bpcol))
//			{
				IChannelFactory<IDuplexSessionChannel> factory =
					binding.BuildChannelFactory<IDuplexSessionChannel> (bpcol);
				
				factory.Open ();
				
				IDuplexSessionChannel channel = factory.CreateChannel (
					new EndpointAddress ("net.tcp://localhost/"));
				
				channel.Open ();
				
				Message message = Message.CreateMessage (
					//channel.Manager.MessageVersion, 
					MessageVersion.Default,
					"Action", "Hello, World, from client side");
				
				channel.Send (message);

				message = channel.Receive ();
				
				Console.WriteLine ("Message received.");
				Console.WriteLine ("Message action: {0}", 
					message.Headers.Action);
				Console.WriteLine ("Message content: {0}", 
					message.GetBody<string> ());

				message.Close ();
				channel.Close ();
				factory.Close ();
//			}
		}
开发者ID:alesliehughes,项目名称:olive,代码行数:45,代码来源:Client.cs

示例10: ReceiveData

        private static void ReceiveData()
        {
            Console.WriteLine("Receiving data:");
            Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisReceiveTransportBinding());
            EndpointAddress address = new EndpointAddress("redis://localhost:6379");

            IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>();
            factory.Open();
            IRequestChannel channel = factory.CreateChannel(address);
            channel.Open();
            Message requestMessage = Message.CreateMessage(MessageVersion.Default, "http://tempuri", "Key");
            Message replyMessage = channel.Request(requestMessage, TimeSpan.FromSeconds(5));
            using (replyMessage)
            {
                Console.WriteLine("Processing reply: {0}", replyMessage.Headers.Action);
                Console.WriteLine("Reply: {0}", replyMessage.GetBody<string>());
            }
        }
开发者ID:nnyegaard,项目名称:REWBI,代码行数:18,代码来源:Program.cs

示例11: RequestReplyChannelFactory_Open

    // Create the channel factory and open the channel for the request-reply message exchange pattern.
    public static void RequestReplyChannelFactory_Open()
    {
        try
        {
            BindingElement[] bindingElements = new BindingElement[2];
            bindingElements[0] = new TextMessageEncodingBindingElement();
            bindingElements[1] = new HttpTransportBindingElement();
            CustomBinding binding = new CustomBinding(bindingElements);

            // Create the channel factory
            IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
            factory.Open();

            // Create the channel and open it.  Success is anything other than an exception.
            IRequestChannel channel = factory.CreateChannel(new EndpointAddress("http://localhost/WcfProjectNService.svc"));
            channel.Open();
        }
        catch (Exception ex)
        {
            Assert.True(false, String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }
    }
开发者ID:weshaggard,项目名称:wcf,代码行数:23,代码来源:CustomBindingTest.cs

示例12: CheckDuplicateAuthenticatorTypesClient

		public void CheckDuplicateAuthenticatorTypesClient ()
		{
			SymmetricSecurityBindingElement be =
				new SymmetricSecurityBindingElement ();
			be.ProtectionTokenParameters =
				new X509SecurityTokenParameters ();
			be.EndpointSupportingTokenParameters.Endorsing.Add (
				new X509SecurityTokenParameters ());
			// This causes multiple supporting token authenticator
			// of the same type.
			be.OptionalEndpointSupportingTokenParameters.Endorsing.Add (
				new X509SecurityTokenParameters ());
			Binding b = new CustomBinding (be, new HttpTransportBindingElement ());
			ClientCredentials cred = new ClientCredentials ();
			cred.ClientCertificate.Certificate =
				new X509Certificate2 ("Test/Resources/test.pfx", "mono");
			IChannelFactory<IReplyChannel> ch = b.BuildChannelFactory<IReplyChannel> (new Uri ("http://localhost:" + NetworkHelpers.FindFreePort ()), cred);
			try {
				ch.Open ();
			} finally {
				if (ch.State == CommunicationState.Closed)
					ch.Close ();
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:24,代码来源:SecurityBindingElementTest.cs

示例13: OpenRequestNonAuthenticatable

		public void OpenRequestNonAuthenticatable ()
		{
			SymmetricSecurityBindingElement sbe = 
				new SymmetricSecurityBindingElement ();
			sbe.ProtectionTokenParameters =
				new UserNameSecurityTokenParameters ();
			Binding binding = new CustomBinding (sbe, new HandlerTransportBindingElement (null));
			BindingParameterCollection pl =
				new BindingParameterCollection ();
			ClientCredentials cred = new ClientCredentials ();
			cred.UserName.UserName = "mono";
			pl.Add (cred);
			IChannelFactory<IRequestChannel> f =
				binding.BuildChannelFactory<IRequestChannel> (pl);
			f.Open ();
			IRequestChannel ch = f.CreateChannel (new EndpointAddress ("stream:dummy"));
			try {
				ch.Open ();
				Assert.Fail ("NotSupportedException is expected.");
			} catch (NotSupportedException) {
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:22,代码来源:SymmetricSecurityBindingElementTest.cs

示例14: IRequestChannel_Http_CustomBinding

    public static void IRequestChannel_Http_CustomBinding()
    {
        IChannelFactory<IRequestChannel> factory = null;
        IRequestChannel channel = null;
        Message replyMessage = null;

        try
        {
            // *** SETUP *** \\
            BindingElement[] bindingElements = new BindingElement[2];
            bindingElements[0] = new TextMessageEncodingBindingElement();
            bindingElements[1] = new HttpTransportBindingElement();
            CustomBinding binding = new CustomBinding(bindingElements);

            // Create the channel factory for the request-reply message exchange pattern.
            factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
            factory.Open();

            // Create the channel.
            channel = factory.CreateChannel(new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
            channel.Open();

            // Create the Message object to send to the service.
            Message requestMessage = Message.CreateMessage(
                binding.MessageVersion,
                action,
                new CustomBodyWriter(clientMessage));

            // *** EXECUTE *** \\
            // Send the Message and receive the Response.
            replyMessage = channel.Request(requestMessage);

            // *** VALIDATE *** \\
            string replyMessageAction = replyMessage.Headers.Action;
            Assert.Equal(action + "Response", replyMessageAction);

            var replyReader = replyMessage.GetReaderAtBodyContents();
            string actualResponse = replyReader.ReadElementContentAsString();
            string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
            Assert.Equal(expectedResponse, actualResponse);

            // *** CLEANUP *** \\
            replyMessage.Close();
            channel.Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(channel, factory);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:52,代码来源:RequestReplyChannelShapeTests.4.0.0.cs

示例15: CustomTransportDoesNotRequireMessageEncoding

		public void CustomTransportDoesNotRequireMessageEncoding ()
		{
			ReplyHandler replier = delegate (Message msg) {
				resmsg = msg;
			};

			RequestReceiver receiver = delegate () {
				return reqmsg;
			};

			RequestSender sender = delegate (Message msg) {
				reqmsg = msg;

				CustomBinding br = new CustomBinding (
					new HandlerTransportBindingElement (replier, receiver));
				IChannelListener<IReplyChannel> l =
					br.BuildChannelListener<IReplyChannel> (
						new BindingParameterCollection ());
				l.Open ();
				IReplyChannel rch = l.AcceptChannel ();
				rch.Open ();
				Message res = Message.CreateMessage (MessageVersion.Default, "urn:succeeded");
				rch.ReceiveRequest ().Reply (res);
				rch.Close ();
				l.Close ();

				return resmsg;
			};

			CustomBinding bs = new CustomBinding (
				new HandlerTransportBindingElement (sender));

			IChannelFactory<IRequestChannel> f =
				bs.BuildChannelFactory<IRequestChannel> (
					new BindingParameterCollection ());
			f.Open ();
			IRequestChannel ch = f.CreateChannel (new EndpointAddress ("urn:dummy"));
			ch.Open ();
			Message result = ch.Request (Message.CreateMessage (MessageVersion.Default, "urn:request"));
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:40,代码来源:CustomBindingTest.cs


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