Handle multiple concurrent calls to BeginTryReceiveRequest
[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                 MetadataExporter exporter;
45
46                 public ServiceMetadataBehavior ()
47                 {
48                 }
49
50                 public bool HttpGetEnabled { get; set; }
51
52                 public bool HttpsGetEnabled { get; set; }
53
54                 public MetadataExporter MetadataExporter {
55                         get { return exporter ?? (exporter = new WsdlExporter ()); }
56                         set { exporter = value; }
57                 }
58
59                 public Uri ExternalMetadataLocation { get; set; }
60
61                 public Uri HttpGetUrl { get; set; }
62
63                 public Uri HttpsGetUrl { get; set; }
64
65                 public Binding HttpGetBinding { get; set; }
66
67                 public Binding HttpsGetBinding { get; set; }
68
69                 void IServiceBehavior.AddBindingParameters (
70                         ServiceDescription description,
71                         ServiceHostBase serviceHostBase,
72                         Collection<ServiceEndpoint> endpoints,
73                         BindingParameterCollection parameters)
74                 {
75                 }
76
77                 void IServiceBehavior.ApplyDispatchBehavior (
78                         ServiceDescription description,
79                         ServiceHostBase serviceHostBase) {
80
81                         ServiceMetadataExtension sme = ServiceMetadataExtension.EnsureServiceMetadataExtension (serviceHostBase);
82
83                         //Find ChannelDispatcher for Mex, and add a MexInstanceContextProvider
84                         //to it
85                         foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) {
86                                 ChannelDispatcher cd = cdb as ChannelDispatcher;
87                                 if (cd == null)
88                                         continue;
89
90                                 foreach (EndpointDispatcher ed in cd.Endpoints) {
91                                         if (ed.ContractName == MexContractName)
92                                                 ed.DispatchRuntime.InstanceContextProvider = new MexInstanceContextProvider (serviceHostBase);
93                                 }
94                         }
95
96                         if (HttpGetEnabled) {
97                                 Uri uri = serviceHostBase.CreateUri ("http", HttpGetUrl);
98                                 if (uri != null)
99                                         sme.EnsureChannelDispatcher (true, "http", uri, HttpGetBinding);
100                         }
101
102                         if (HttpsGetEnabled) {
103                                 Uri uri = serviceHostBase.CreateUri ("https", HttpsGetUrl);
104                                 if (uri != null)
105                                         sme.EnsureChannelDispatcher (true, "https", uri, HttpsGetBinding);
106                         }
107                 }
108
109                 [MonoTODO]
110                 void IServiceBehavior.Validate (
111                         ServiceDescription description,
112                         ServiceHostBase serviceHostBase)
113                 {                       
114                 }
115         }
116 }