2 // TcpChannelFactory.cs
5 // Marcos Cobena (marcoscobena@gmail.com)
7 // Copyright 2007 Marcos Cobena (http://www.youcannoteatbits.org/)
11 using System.Collections.Generic;
13 using System.Net.Security;
14 using System.ServiceModel;
15 using System.ServiceModel.Description;
16 using System.ServiceModel.Security;
19 namespace System.ServiceModel.Channels
21 internal class TcpChannelInfo
23 public TcpChannelInfo (TcpTransportBindingElement element, MessageEncoder encoder)
25 this.element = element;
26 this.encoder = encoder;
29 TcpTransportBindingElement element;
30 MessageEncoder encoder;
32 public TcpTransportBindingElement BindingElement {
33 get { return element; }
36 public MessageEncoder MessageEncoder {
37 get { return encoder; }
41 internal class TcpChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
46 public TcpChannelFactory (TcpTransportBindingElement source, BindingContext ctx)
48 MessageEncoder encoder = null;
49 foreach (BindingElement be in ctx.RemainingBindingElements) {
50 MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
52 encoder = mbe.CreateMessageEncoderFactory ().Encoder;
57 encoder = new BinaryMessageEncoder ();
58 info = new TcpChannelInfo (source, encoder);
62 protected override TChannel OnCreateChannel (
63 EndpointAddress address, Uri via)
65 ThrowIfDisposedOrNotOpen ();
67 if (info.BindingElement.Scheme != address.Uri.Scheme)
68 throw new ArgumentException (String.Format ("Argument EndpointAddress has unsupported URI scheme: {0}", address.Uri.Scheme));
70 Type t = typeof (TChannel);
72 if (t == typeof (IDuplexSessionChannel))
73 return (TChannel) (object) new TcpDuplexSessionChannel (this, info, address, via);
75 throw new InvalidOperationException (String.Format ("Channel type {0} is not supported.", typeof (TChannel).Name));
79 protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
80 AsyncCallback callback, object state)
82 throw new NotImplementedException ();
86 protected override void OnEndOpen (IAsyncResult result)
88 throw new NotImplementedException ();
92 protected override void OnOpen (TimeSpan timeout)