2 // Author: Atsushi Enomoto <atsushi@ximian.com>
4 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 using System.ComponentModel;
28 using System.Configuration;
30 using System.ServiceModel.Configuration;
31 using System.ServiceModel.Description;
33 namespace System.ServiceModel.Discovery.Configuration
35 public class UdpDiscoveryEndpointElement : DiscoveryEndpointElement
37 static ConfigurationPropertyCollection properties;
38 static ConfigurationProperty discovery_mode, max_response_delay, multicast_address, transport_settings;
40 static UdpDiscoveryEndpointElement ()
42 discovery_mode = new ConfigurationProperty ("discoveryMode", typeof (ServiceDiscoveryMode), ServiceDiscoveryMode.Adhoc, null, null, ConfigurationPropertyOptions.None);
43 max_response_delay = new ConfigurationProperty ("maxResponseDelay", typeof (TimeSpan), "00:00:00.500", new TimeSpanConverter (), null, ConfigurationPropertyOptions.None);
44 multicast_address = new ConfigurationProperty ("multicastAddress", typeof (Uri), "soap.udp://239.255.255.250:3702", new UriTypeConverter (), null, ConfigurationPropertyOptions.None);
45 transport_settings = new ConfigurationProperty ("transportSettings", typeof (UdpTransportSettingsElement), null, null, null, ConfigurationPropertyOptions.None);
46 properties = new ConfigurationPropertyCollection ();
47 properties.Add (discovery_mode);
48 properties.Add (max_response_delay);
49 properties.Add (multicast_address);
50 properties.Add (transport_settings);
53 public UdpDiscoveryEndpointElement ()
57 [ConfigurationProperty ("discoveryMode", DefaultValue = ServiceDiscoveryMode.Adhoc)]
58 public new ServiceDiscoveryMode DiscoveryMode {
59 get { return (ServiceDiscoveryMode) base [discovery_mode]; }
60 set { base [discovery_mode] = value; }
63 protected override Type EndpointType {
64 get { return typeof (UdpDiscoveryEndpoint); }
67 [TypeConverter (typeof (TimeSpanConverter))]
68 [ConfigurationProperty ("maxResponseDelay", DefaultValue = "00:00:00.500")]
69 public new TimeSpan MaxResponseDelay {
70 get { return (TimeSpan) base [max_response_delay]; }
71 set { base [max_response_delay] = value; }
74 [ConfigurationProperty ("multicastAddress", DefaultValue = "soap.udp://239.255.255.250:3702")]
75 public Uri MulticastAddress {
76 get { return (Uri) base [multicast_address]; }
77 set { base [multicast_address] = value; }
80 [ConfigurationProperty ("transportSettings")]
81 public UdpTransportSettingsElement TransportSettings {
82 get { return (UdpTransportSettingsElement) base [transport_settings]; }
85 protected override ConfigurationPropertyCollection Properties {
86 get { return properties; }
89 protected override ServiceEndpoint CreateServiceEndpoint (ContractDescription contractDescription)
91 if (contractDescription == null)
92 throw new ArgumentNullException ("contractDescription");
93 DiscoveryVersion ver = null;
94 switch (contractDescription.ContractType.Namespace) {
95 case DiscoveryVersion.Namespace11:
96 ver = DiscoveryVersion.WSDiscovery11;
98 case DiscoveryVersion.NamespaceApril2005:
99 ver = DiscoveryVersion.WSDiscoveryApril2005;
101 case DiscoveryVersion.NamespaceCD1:
102 ver = DiscoveryVersion.WSDiscoveryCD1;
105 var ret = new UdpDiscoveryEndpoint (ver, MulticastAddress);
106 ret.MaxResponseDelay = MaxResponseDelay;
107 TransportSettings.ApplyConfiguration (ret.TransportSettings);
111 protected override void InitializeFrom (ServiceEndpoint endpoint)
113 if (endpoint == null)
114 throw new ArgumentNullException ("endpoint");
115 var e = (UdpDiscoveryEndpoint) endpoint;
116 MaxResponseDelay = e.MaxResponseDelay;
117 MulticastAddress = e.MulticastAddress;
118 TransportSettings.InitializeFrom (e.TransportSettings);
121 protected override void OnApplyConfiguration (ServiceEndpoint endpoint, ChannelEndpointElement serviceEndpointElement)
123 if (endpoint == null)
124 throw new ArgumentNullException ("endpoint");
125 var de = (DiscoveryEndpoint) endpoint;
126 if (!de.DiscoveryVersion.Equals (DiscoveryVersion))
127 throw new ArgumentException ("Argument AnnouncementEndpoint is initialized with different DiscoveryVersion");
128 de.MaxResponseDelay = MaxResponseDelay;
129 de.Address = serviceEndpointElement.CreateEndpointAddress (); // it depends on InternalVisibleTo(System.ServiceModel)
130 var be = (UdpTransportBindingElement) de.Binding.CreateBindingElements ().First (b => b is UdpTransportBindingElement);
131 TransportSettings.ApplyConfiguration (be.TransportSettings);
134 protected override void OnApplyConfiguration (ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement)
136 if (endpoint == null)
137 throw new ArgumentNullException ("endpoint");
138 var de = (DiscoveryEndpoint) endpoint;
139 if (!de.DiscoveryVersion.Equals (DiscoveryVersion))
140 throw new ArgumentException ("Argument AnnouncementEndpoint is initialized with different DiscoveryVersion");
141 de.MaxResponseDelay = MaxResponseDelay;
142 de.Address = serviceEndpointElement.CreateEndpointAddress (); // it depends on InternalVisibleTo(System.ServiceModel)
143 var be = (UdpTransportBindingElement) de.Binding.CreateBindingElements ().First (b => b is UdpTransportBindingElement);
144 TransportSettings.ApplyConfiguration (be.TransportSettings);
147 protected override void OnInitializeAndValidate (ChannelEndpointElement channelEndpointElement)
149 // It seems to do nothing.
150 base.OnInitializeAndValidate (channelEndpointElement);
153 protected override void OnInitializeAndValidate (ServiceEndpointElement channelEndpointElement)
155 // It seems to do nothing.
156 base.OnInitializeAndValidate (channelEndpointElement);