2 // PeerTransportBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections.Generic;
31 using System.Net.Security;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Description;
35 namespace System.ServiceModel.Channels
38 public sealed class PeerTransportBindingElement
39 : TransportBindingElement, IPolicyExportExtension, IWsdlExportExtension
41 long max_recv_message_size = 0x10000;
43 PeerSecuritySettings security = new PeerSecuritySettings ();
45 public PeerTransportBindingElement ()
49 private PeerTransportBindingElement (
50 PeerTransportBindingElement other)
53 max_recv_message_size = other.max_recv_message_size;
55 other.security.CopyTo (security);
58 public IPAddress ListenIPAddress { get; set; }
60 public override long MaxReceivedMessageSize {
61 get { return max_recv_message_size; }
62 set { max_recv_message_size = value; }
70 public override string Scheme {
71 get { return "net.p2p"; }
74 public override bool CanBuildChannelFactory<TChannel> (
75 BindingContext context)
77 return typeof (TChannel) == typeof (IOutputChannel) ||
78 typeof (TChannel) == typeof (IDuplexChannel);
81 public override bool CanBuildChannelListener<TChannel> (
82 BindingContext context)
84 return typeof (TChannel) == typeof (IInputChannel) ||
85 typeof (TChannel) == typeof (IDuplexChannel);
88 public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
89 BindingContext context)
91 if (!CanBuildChannelFactory<TChannel> (context))
92 throw new ArgumentException (String.Format ("Not supported channel type '{0}'", typeof (TChannel)));
93 if (typeof (TChannel) == typeof (IOutputChannel))
94 return (IChannelFactory<TChannel>) (object) new PeerChannelFactory<IOutputChannel> (this, context);
95 else if (typeof (TChannel) == typeof (IDuplexChannel))
96 return (IChannelFactory<TChannel>) (object) new PeerChannelFactory<IDuplexChannel> (this, context);
97 throw new InvalidOperationException (String.Format ("Not supported channel '{0}' (is incorrectly allowed at construction time)", typeof (TChannel)));
100 public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
101 BindingContext context)
103 if (!CanBuildChannelListener<TChannel> (context))
104 throw new ArgumentException (String.Format ("Not supported channel type '{0}'", typeof (TChannel)));
106 // FIXME: check LocalIPAddress.
108 if (typeof (TChannel) == typeof (IInputChannel))
109 return (IChannelListener<TChannel>) (object) new PeerChannelListener<IInputChannel> (this, context);
110 else if (typeof (TChannel) == typeof (IDuplexChannel))
111 return (IChannelListener<TChannel>) (object) new PeerChannelListener<IDuplexChannel> (this, context);
112 throw new InvalidOperationException (String.Format ("Not supported channel '{0}' (is incorrectly allowed at construction time)", typeof (TChannel)));
115 public override BindingElement Clone ()
117 return new PeerTransportBindingElement (this);
120 public override T GetProperty<T> (BindingContext context)
122 if (typeof (T) == typeof (IBindingMulticastCapabilities))
123 return (T) (object) this;
124 if (typeof (T) == typeof (ISecurityCapabilities))
125 return (T) (object) this;
126 if (typeof (T) == typeof (IBindingDeliveryCapabilities))
127 return (T) (object) this;
132 public PeerSecuritySettings Security {
133 get { return security; }
137 void IPolicyExportExtension.ExportPolicy (MetadataExporter exporter, PolicyConversionContext contxt)
139 throw new NotImplementedException ();
143 void IWsdlExportExtension.ExportEndpoint (WsdlExporter exporter, WsdlEndpointConversionContext context)
145 throw new NotImplementedException ();
149 void IWsdlExportExtension.ExportContract (WsdlExporter exporter, WsdlContractConversionContext context)
151 throw new NotImplementedException ();