本文整理汇总了C#中HttpTransportBindingElement.BuildChannelFactory方法的典型用法代码示例。如果您正苦于以下问题:C# HttpTransportBindingElement.BuildChannelFactory方法的具体用法?C# HttpTransportBindingElement.BuildChannelFactory怎么用?C# HttpTransportBindingElement.BuildChannelFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpTransportBindingElement
的用法示例。
在下文中一共展示了HttpTransportBindingElement.BuildChannelFactory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main ()
{
HttpTransportBindingElement el =
new HttpTransportBindingElement ();
IChannelFactory<IRequestChannel> factory =
el.BuildChannelFactory<IRequestChannel> (
new BindingContext (new CustomBinding (),
new BindingParameterCollection ()));
factory.Open ();
IRequestChannel request = factory.CreateChannel (
new EndpointAddress ("http://localhost:37564"));
request.Open ();
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
Message.CreateMessage (MessageVersion.Default, "Echo")
.WriteMessage (w);
}
Console.WriteLine ();
Message msg = request.Request (
Message.CreateMessage (MessageVersion.Default, "Echo"),
TimeSpan.FromSeconds (15));
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
msg.WriteMessage (w);
}
}
示例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);
}
示例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 ();
}
}
示例4: GetChannelManagerBase
public static ChannelManagerBase GetChannelManagerBase()
{
HttpTransportBindingElement httpBE = new HttpTransportBindingElement();
CustomBinding binding = new CustomBinding(httpBE);
return (ChannelManagerBase)httpBE.BuildChannelFactory<IRequestChannel>(new BindingContext(binding, new BindingParameterCollection()));
}
示例5: ConsumeBindingElements
// Now this test is mostly useless ...
public void ConsumeBindingElements ()
{
BindingContext ctx = new BindingContext (
new CustomBinding (
new TextMessageEncodingBindingElement (),
new HttpTransportBindingElement ()),
new BindingParameterCollection ());
HttpTransportBindingElement be =
new HttpTransportBindingElement ();
be.BuildChannelFactory<IRequestChannel> (ctx);
}