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


C# HttpTransportBindingElement.BuildChannelListener方法代码示例

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


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

示例1: Main

	public static void Main ()
	{
		HttpTransportBindingElement el =
			new HttpTransportBindingElement ();
		BindingContext bc = new BindingContext (
			new CustomBinding (),
			new BindingParameterCollection (),
			new Uri ("http://localhost:37564"),
			String.Empty, ListenUriMode.Explicit);
		IChannelListener<IReplyChannel> listener =
			el.BuildChannelListener<IReplyChannel> (bc);

		listener.Open ();

		IReplyChannel reply = listener.AcceptChannel ();

		reply.Open ();

		if (!reply.WaitForRequest (TimeSpan.FromSeconds (10))) {
			Console.WriteLine ("No request reached here.");
			return;
		}
		Console.WriteLine ("Receiving request ...");
		RequestContext ctx = reply.ReceiveRequest ();
		if (ctx == null)
			return;
		Console.WriteLine ("Starting reply ...");
		ctx.Reply (Message.CreateMessage (MessageVersion.Default, "Ack"));
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:29,代码来源:reply.cs

示例2: Main

	public static void Main ()
	{
		HttpTransportBindingElement el =
			new HttpTransportBindingElement ();
		IChannelListener<IReplyChannel> listener =
			el.BuildChannelListener<IReplyChannel> (
				new BindingContext (new CustomBinding (),
					new BindingParameterCollection (),
					new Uri ("http://localhost:37564"),
					String.Empty, ListenUriMode.Explicit));
		IChannelFactory<IRequestChannel> factory =
			el.BuildChannelFactory<IRequestChannel> (
				new BindingContext (new CustomBinding (),
					new BindingParameterCollection ()));

		listener.Open ();
		factory.Open ();

		IRequestChannel request = factory.CreateChannel (
			new EndpointAddress ("http://localhost:37564"));
		IReplyChannel reply = listener.AcceptChannel ();

		reply.Open ();
		request.Open ();

		new Thread (delegate () { try { RunListener (reply); } catch (Exception ex) { Console.WriteLine (ex); } }).Start ();
		Message msg = request.Request (Message.CreateMessage (
			MessageVersion.Default, "Echo"), TimeSpan.FromSeconds (15));
		XmlWriterSettings settings = new XmlWriterSettings ();
		settings.OmitXmlDeclaration = true;
		StringWriter sw = new StringWriter ();
		using (XmlWriter w = XmlWriter.Create (sw, settings)) {
			msg.WriteMessage (w);
		}
		Console.WriteLine (sw);
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:36,代码来源:self-request-reply.cs

示例3: LowLevelHttpConnection

		// It is almost identical to http-low-level-binding
		public void LowLevelHttpConnection ()
		{
			HttpTransportBindingElement lel =
				new HttpTransportBindingElement ();

			// Service
			BindingContext lbc = new BindingContext (
				new CustomBinding (),
				new BindingParameterCollection (),
				new Uri ("http://localhost:37564"),
				String.Empty, ListenUriMode.Explicit);
			listener = lel.BuildChannelListener<IReplyChannel> (lbc);

			try {

			listener.Open ();

			svcret = "";

			Thread svc = new Thread (delegate () {
				try {
					svcret = LowLevelHttpConnection_SetupService ();
				} catch (Exception ex) {
					svcret = ex.ToString ();
				}
			});
			svc.Start ();

			// Client code goes here.

			HttpTransportBindingElement el =
				new HttpTransportBindingElement ();
			BindingContext ctx = new BindingContext (
				new CustomBinding (),
				new BindingParameterCollection ());
			IChannelFactory<IRequestChannel> factory =
				el.BuildChannelFactory<IRequestChannel> (ctx);

			factory.Open ();

			IRequestChannel request = factory.CreateChannel (
				new EndpointAddress ("http://localhost:37564"));

			request.Open ();

			try {
			try {
				Message reqmsg = Message.CreateMessage (
					MessageVersion.Default, "Echo");
				// sync version does not work here.
				Message msg = request.Request (reqmsg, TimeSpan.FromSeconds (5));

				using (XmlWriter w = XmlWriter.Create (TextWriter.Null)) {
					msg.WriteMessage (w);
				}

				if (svcret != null)
					Assert.Fail (svcret.Length > 0 ? svcret : "service code did not finish until this test expected.");
			} finally {
				if (request.State == CommunicationState.Opened)
					request.Close ();
			}
			} finally {
				if (factory.State == CommunicationState.Opened)
					factory.Close ();
			}
			} finally {
				if (listener.State == CommunicationState.Opened)
					listener.Close ();
			}
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:72,代码来源:HttpTransportBindingElementTest.cs


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