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 bool enable_http, enable_https;
45 Uri http_url, https_url, location;
46 MetadataExporter exporter;
48 public ServiceMetadataBehavior ()
52 public bool HttpGetEnabled {
53 get { return enable_http; }
54 set { enable_http = value; }
57 public bool HttpsGetEnabled {
58 get { return enable_https; }
59 set { enable_https = value; }
62 public MetadataExporter MetadataExporter {
63 get { return exporter ?? (exporter = new WsdlExporter ()); }
64 set { exporter = value; }
67 public Uri ExternalMetadataLocation {
68 get { return location; }
69 set { location = value; }
72 public Uri HttpGetUrl {
73 get { return http_url; }
74 set { http_url = value; }
77 public Uri HttpsGetUrl {
78 get { return https_url; }
79 set { https_url = value; }
83 void IServiceBehavior.AddBindingParameters (
84 ServiceDescription description,
85 ServiceHostBase serviceHostBase,
86 Collection<ServiceEndpoint> endpoints,
87 BindingParameterCollection parameters)
91 void IServiceBehavior.ApplyDispatchBehavior (
92 ServiceDescription description,
93 ServiceHostBase serviceHostBase) {
95 ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension (description, serviceHostBase);
97 //Find ChannelDispatcher for Mex, and add a MexInstanceContextProvider
99 foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
100 ChannelDispatcher cd = cdb as ChannelDispatcher;
104 foreach (EndpointDispatcher ed in cd.Endpoints) {
105 if (ed.ContractName == MexContractName)
106 ed.DispatchRuntime.InstanceContextProvider = new MexInstanceContextProvider (serviceHostBase);
110 if (HttpGetEnabled) {
111 Uri uri = serviceHostBase.CreateUri ("http", HttpGetUrl);
113 ServiceMetadataExtension.EnsureServiceMetadataHttpChanelDispatcher (description, serviceHostBase, sme, uri);
116 if (HttpsGetEnabled) {
117 Uri uri = serviceHostBase.CreateUri ("https", HttpsGetUrl);
119 ServiceMetadataExtension.EnsureServiceMetadataHttpsChanelDispatcher (description, serviceHostBase, sme, uri);
124 void IServiceBehavior.Validate (
125 ServiceDescription description,
126 ServiceHostBase serviceHostBase)