2 // ServiceMetadataBehavior.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Ankit Jain <jankit@novell.com>
8 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections.Generic;
31 using System.Collections.ObjectModel;
32 using System.Runtime.Serialization;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Dispatcher;
35 using System.ServiceModel.Description;
37 namespace System.ServiceModel.Description
40 public class ServiceMetadataBehavior : IServiceBehavior
42 public const string MexContractName = "IMetadataExchange";
44 MetadataExporter exporter;
46 public ServiceMetadataBehavior ()
50 public bool HttpGetEnabled { get; set; }
52 public bool HttpsGetEnabled { get; set; }
54 public MetadataExporter MetadataExporter {
55 get { return exporter ?? (exporter = new WsdlExporter ()); }
56 set { exporter = value; }
59 public Uri ExternalMetadataLocation { get; set; }
61 public Uri HttpGetUrl { get; set; }
63 public Uri HttpsGetUrl { get; set; }
65 public Binding HttpGetBinding { get; set; }
67 public Binding HttpsGetBinding { get; set; }
69 void IServiceBehavior.AddBindingParameters (
70 ServiceDescription description,
71 ServiceHostBase serviceHostBase,
72 Collection<ServiceEndpoint> endpoints,
73 BindingParameterCollection parameters)
77 void IServiceBehavior.ApplyDispatchBehavior (
78 ServiceDescription description,
79 ServiceHostBase serviceHostBase) {
81 ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension (serviceHostBase);
83 //Find ChannelDispatcher for Mex, and add a MexInstanceContextProvider
85 foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
86 ChannelDispatcher cd = cdb as ChannelDispatcher;
90 foreach (EndpointDispatcher ed in cd.Endpoints) {
91 if (ed.ContractName == MexContractName)
92 ed.DispatchRuntime.InstanceContextProvider = new MexInstanceContextProvider (serviceHostBase);
97 Uri uri = serviceHostBase.CreateUri ("http", HttpGetUrl);
99 sme.EnsureChannelDispatcher (true, "http", uri, HttpGetBinding);
102 if (HttpsGetEnabled) {
103 Uri uri = serviceHostBase.CreateUri ("https", HttpsGetUrl);
105 sme.EnsureChannelDispatcher (true, "https", uri, HttpsGetBinding);
110 void IServiceBehavior.Validate (
111 ServiceDescription description,
112 ServiceHostBase serviceHostBase)