2009-08-07 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Description / ServiceMetadataBehavior.cs
1 //
2 // ServiceMetadataBehavior.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //      Ankit Jain  <jankit@novell.com>
7 //
8 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29 using System;
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;
36
37 namespace System.ServiceModel.Description
38 {
39         [MonoTODO]
40         public class ServiceMetadataBehavior : IServiceBehavior
41         {
42                 public const string MexContractName = "IMetadataExchange";
43
44                 bool enable_http, enable_https;
45                 Uri http_url, https_url, location;
46                 MetadataExporter exporter;
47
48                 public ServiceMetadataBehavior ()
49                 {
50                 }
51
52                 public bool HttpGetEnabled {
53                         get { return enable_http; }
54                         set { enable_http = value; }
55                 }
56
57                 public bool HttpsGetEnabled {
58                         get { return enable_https; }
59                         set { enable_https = value; }
60                 }
61
62                 public MetadataExporter MetadataExporter {
63                         get { return exporter ?? (exporter = new WsdlExporter ()); }
64                         set { exporter = value; }
65                 }
66
67                 public Uri ExternalMetadataLocation {
68                         get { return location; }
69                         set { location = value; }
70                 }
71
72                 public Uri HttpGetUrl {
73                         get { return http_url; }
74                         set { http_url = value; }
75                 }
76
77                 public Uri HttpsGetUrl {
78                         get { return https_url; }
79                         set { https_url = value; }
80                 }
81
82                 [MonoTODO]
83                 void IServiceBehavior.AddBindingParameters (
84                         ServiceDescription description,
85                         ServiceHostBase serviceHostBase,
86                         Collection<ServiceEndpoint> endpoints,
87                         BindingParameterCollection parameters)
88                 {
89                 }
90
91                 void IServiceBehavior.ApplyDispatchBehavior (
92                         ServiceDescription description,
93                         ServiceHostBase serviceHostBase) {
94
95                         ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension (description, serviceHostBase);
96
97                         //Find ChannelDispatcher for Mex, and add a MexInstanceContextProvider
98                         //to it
99                         foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
100                                 ChannelDispatcher cd = cdb as ChannelDispatcher;
101                                 if (cd == null)
102                                         continue;
103
104                                 foreach (EndpointDispatcher ed in cd.Endpoints) {
105                                         if (ed.ContractName == MexContractName)
106                                                 ed.DispatchRuntime.InstanceContextProvider = new MexInstanceContextProvider (serviceHostBase);
107                                 }
108                         }
109
110                         if (HttpGetEnabled) {
111                                 Uri uri = serviceHostBase.CreateUri ("http", HttpGetUrl);
112                                 if (uri != null)
113                                         ServiceMetadataExtension.EnsureServiceMetadataHttpChanelDispatcher (description, serviceHostBase, sme, uri);
114                         }
115
116                         if (HttpsGetEnabled) {
117                                 Uri uri = serviceHostBase.CreateUri ("https", HttpsGetUrl);
118                                 if (uri != null)
119                                         ServiceMetadataExtension.EnsureServiceMetadataHttpsChanelDispatcher (description, serviceHostBase, sme, uri);
120                         }
121                 }
122
123                 [MonoTODO]
124                 void IServiceBehavior.Validate (
125                         ServiceDescription description,
126                         ServiceHostBase serviceHostBase)
127                 {                       
128                 }
129         }
130 }