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.
26 using System.ComponentModel;
27 using System.Configuration;
29 using System.ServiceModel.Configuration;
30 using System.ServiceModel.Description;
31 using System.ServiceModel.Discovery.Udp;
33 namespace System.ServiceModel.Discovery.Configuration
35 public class UdpAnnouncementEndpointElement : AnnouncementEndpointElement
37 static ConfigurationPropertyCollection properties;
38 static ConfigurationProperty max_announcement_delay, multicast_address, transport_settings;
40 static UdpAnnouncementEndpointElement ()
42 max_announcement_delay = new ConfigurationProperty ("maxAnnouncementDelay", typeof (TimeSpan), "00:00:00.500", new TimeSpanConverter (), null, ConfigurationPropertyOptions.None);
43 multicast_address = new ConfigurationProperty ("multicastAddress", typeof (Uri), "soap.udp://239.255.255.250:3702", new UriTypeConverter (), null, ConfigurationPropertyOptions.None);
44 transport_settings = new ConfigurationProperty ("transportSettings", typeof (UdpTransportSettingsElement), null, null, null, ConfigurationPropertyOptions.None);
45 properties = new ConfigurationPropertyCollection ();
46 properties.Add (max_announcement_delay);
47 properties.Add (multicast_address);
48 properties.Add (transport_settings);
51 public UdpAnnouncementEndpointElement ()
55 protected internal override Type EndpointType {
56 get { return typeof (UdpAnnouncementEndpoint); }
59 [TypeConverter (typeof (TimeSpanConverter))]
60 [ConfigurationPropertyAttribute("maxAnnouncementDelay", DefaultValue = "00:00:00.500")]
61 public new TimeSpan MaxAnnouncementDelay {
62 get { return (TimeSpan) base [max_announcement_delay]; }
63 set { base [max_announcement_delay] = value; }
66 [ConfigurationPropertyAttribute("multicastAddress", DefaultValue = "soap.udp://239.255.255.250:3702")]
67 public Uri MulticastAddress {
68 get { return (Uri) base [multicast_address]; }
69 set { base [multicast_address] = value; }
72 [ConfigurationPropertyAttribute("transportSettings")]
73 public UdpTransportSettingsElement TransportSettings {
74 get { return (UdpTransportSettingsElement) base [transport_settings]; }
77 protected override ConfigurationPropertyCollection Properties {
78 get { return properties; }
81 protected internal override ServiceEndpoint CreateServiceEndpoint (ContractDescription contractDescription)
83 if (contractDescription == null)
84 throw new ArgumentNullException ("contractDescription");
85 DiscoveryVersion ver = null;
86 switch (contractDescription.ContractType.Namespace) {
87 case DiscoveryVersion.Namespace11:
88 ver = DiscoveryVersion.WSDiscovery11;
90 case DiscoveryVersion.NamespaceApril2005:
91 ver = DiscoveryVersion.WSDiscoveryApril2005;
93 case DiscoveryVersion.NamespaceCD1:
94 ver = DiscoveryVersion.WSDiscoveryCD1;
97 var ret = new UdpAnnouncementEndpoint (ver, MulticastAddress);
98 ret.MaxAnnouncementDelay = MaxAnnouncementDelay;
99 TransportSettings.ApplyConfiguration (ret.TransportSettings);
103 protected internal override void InitializeFrom (ServiceEndpoint endpoint)
105 if (endpoint == null)
106 throw new ArgumentNullException ("endpoint");
107 var e = (UdpAnnouncementEndpoint) endpoint;
108 MaxAnnouncementDelay = e.MaxAnnouncementDelay;
109 MulticastAddress = e.MulticastAddress;
110 TransportSettings.InitializeFrom (e.TransportSettings);
113 protected override void OnApplyConfiguration (ServiceEndpoint endpoint, ChannelEndpointElement serviceEndpointElement)
115 if (endpoint == null)
116 throw new ArgumentNullException ("endpoint");
117 var de = (AnnouncementEndpoint) endpoint;
118 if (!de.DiscoveryVersion.Equals (DiscoveryVersion))
119 throw new ArgumentException ("Argument AnnouncementEndpoint is initialized with different DiscoveryVersion");
120 de.MaxAnnouncementDelay = MaxAnnouncementDelay;
121 de.Address = serviceEndpointElement.CreateEndpointAddress (); // it depends on InternalVisibleTo(System.ServiceModel)
122 var be = (UdpTransportBindingElement) de.Binding.CreateBindingElements ().First (b => b is UdpTransportBindingElement);
123 TransportSettings.ApplyConfiguration (be.TransportSettings);
126 protected override void OnApplyConfiguration (ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement)
128 if (endpoint == null)
129 throw new ArgumentNullException ("endpoint");
130 var de = (AnnouncementEndpoint) endpoint;
131 if (!de.DiscoveryVersion.Equals (DiscoveryVersion))
132 throw new ArgumentException ("Argument AnnouncementEndpoint is initialized with different DiscoveryVersion");
133 de.MaxAnnouncementDelay = MaxAnnouncementDelay;
134 de.Address = serviceEndpointElement.CreateEndpointAddress (); // it depends on InternalVisibleTo(System.ServiceModel)
135 var be = (UdpTransportBindingElement) de.Binding.CreateBindingElements ().First (b => b is UdpTransportBindingElement);
136 TransportSettings.ApplyConfiguration (be.TransportSettings);
139 protected override void OnInitializeAndValidate (ChannelEndpointElement channelEndpointElement)
141 // It seems to do nothing.
142 base.OnInitializeAndValidate (channelEndpointElement);
145 protected override void OnInitializeAndValidate (ServiceEndpointElement serviceEndpointElement)
147 // It seems to do nothing.
148 base.OnInitializeAndValidate (serviceEndpointElement);