當前位置: 首頁>>代碼示例>>C#>>正文


C# ChannelFactory.Echo方法代碼示例

本文整理匯總了C#中System.ServiceModel.ChannelFactory.Echo方法的典型用法代碼示例。如果您正苦於以下問題:C# ChannelFactory.Echo方法的具體用法?C# ChannelFactory.Echo怎麽用?C# ChannelFactory.Echo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ServiceModel.ChannelFactory的用法示例。


在下文中一共展示了ChannelFactory.Echo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SimpleDuplexBuffered

		public void SimpleDuplexBuffered () // sample[svc|cli]4.exe
		{
			ServiceHost host = new ServiceHost (typeof (Foo));
			var bindingS = new CustomBinding (new BindingElement [] {
				new BinaryMessageEncodingBindingElement (),
				new TcpTransportBindingElement () });
			bindingS.ReceiveTimeout = TimeSpan.FromSeconds (5);
			bindingS.OpenTimeout = TimeSpan.FromSeconds (20);
			host.AddServiceEndpoint (typeof (IFoo),
				bindingS, new Uri ("net.tcp://localhost:37564"));
			host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
			host.Open ();

			try {
				for (int i = 0; i < 2; i++) {
					var bindingC = new NetTcpBinding ();
					bindingC.Security.Mode = SecurityMode.None;
					IFooChannel proxy = new ChannelFactory<IFooChannel> (bindingC, new EndpointAddress ("net.tcp://localhost:37564/")).CreateChannel ();
					proxy.Open ();
					try {
						Assert.AreEqual ("TEST FOR ECHO", proxy.Echo ("TEST FOR ECHO"), "#1");
						var sid = proxy.SessionId;
						Assert.AreEqual (3000, proxy.Add (1000, 2000), "#2");
						Assert.AreEqual (sid, proxy.SessionId, "#3");
					} finally {
						proxy.Close ();
					}
				}
			} catch (Exception ex) {
				Console.Error.WriteLine (ex);
			} finally {
				host.Close ();
			}
		}
開發者ID:nickchal,項目名稱:pash,代碼行數:34,代碼來源:TcpTransportBindingElementTest.cs

示例2: SimpleRequestReplyStreamed

		// FIXME: To enable this, we must fix the "request-reply TCP channel must close the connection" issue.
		// It is strange, but the standalone test just works.
		public void SimpleRequestReplyStreamed () // sample[svc|cli]5.exe
		{
			ServiceHost host = new ServiceHost (typeof (Foo));
			NetTcpBinding bindingS = new NetTcpBinding ();
			bindingS.TransferMode = TransferMode.Streamed;
			bindingS.Security.Mode = SecurityMode.None;
			bindingS.ReceiveTimeout = TimeSpan.FromSeconds (5);
			bindingS.OpenTimeout = TimeSpan.FromSeconds (20);
			host.AddServiceEndpoint (typeof (IFoo),
				bindingS, new Uri ("net.tcp://localhost:37564"));
			host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
			host.Open ();

			try {
				for (int i = 0; i < 2; i++) {
					var bindingC = new NetTcpBinding ();
					bindingS.TransferMode = TransferMode.Streamed;
					bindingC.Security.Mode = SecurityMode.None;
					IFooChannel proxy = new ChannelFactory<IFooChannel> (bindingC, new EndpointAddress ("net.tcp://localhost:37564/")).CreateChannel ();
					proxy.Open ();
					try {
						Assert.AreEqual ("TEST FOR ECHO", proxy.Echo ("TEST FOR ECHO"), "#1");
						Assert.AreEqual (3000, proxy.Add (1000, 2000), "#2");
					} finally {
						proxy.Close ();
					}
				}
			} finally {
				host.Close ();
			}
		}
開發者ID:nickchal,項目名稱:pash,代碼行數:33,代碼來源:TcpTransportBindingElementTest.cs

示例3: ConnectionHttpTransport

		public void ConnectionHttpTransport ()
		{
			var host = new ServiceHost (typeof (Foo));
			var bindingsvc = new CustomBinding (new BindingElement [] {
				new BinaryMessageEncodingBindingElement (),
				new HttpTransportBindingElement () });
			int port = NetworkHelpers.FindFreePort ();
			host.AddServiceEndpoint (typeof (IFoo), bindingsvc, "http://localhost:" + port + "/");
			host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
			host.Open (TimeSpan.FromSeconds (5));
			try {
				for (int i = 0; i < 2; i++) {
					var bindingcli = new CustomBinding (new BindingElement [] {
						new BinaryMessageEncodingBindingElement (),
						new HttpTransportBindingElement () });
					var cli = new ChannelFactory<IFooClient> (bindingcli, new EndpointAddress ("http://localhost:" + port + "/")).CreateChannel ();
					Assert.AreEqual ("test for echo", cli.Echo ("TEST FOR ECHO"), "#1");
					var sid = cli.SessionId;
					Assert.AreEqual (3000, cli.Add (1000, 2000), "#2");
					Assert.AreEqual (sid, cli.SessionId, "#3");
					cli.Close ();
				}
			} finally {
				host.Close (TimeSpan.FromSeconds (5));
				var t = new TcpListener (port);
				t.Start ();
				t.Stop ();
			}
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:29,代碼來源:BinaryMessageEncodingBindingElementTest.cs


注:本文中的System.ServiceModel.ChannelFactory.Echo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。