File: MetadataExchangeBindings.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (217 lines) | stat: -rw-r--r-- 7,067 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

namespace System.ServiceModel.Description
{
    using System.Globalization;
    using System.ServiceModel.Channels;
    using System.ServiceModel;
    using System.Collections.Generic;

    public static class MetadataExchangeBindings
    {
        static Binding httpBinding;
        static Binding httpGetBinding;
        static Binding httpsBinding;
        static Binding httpsGetBinding;
        static Binding tcpBinding;
        static Binding pipeBinding;

        internal static Binding Http
        {
            get
            {
                // don't need to lock because no guarantee of instance identity
                if (httpBinding == null)
                {
                    httpBinding = CreateHttpBinding();
                }

                return httpBinding;
            }
        }

        internal static Binding HttpGet
        {
            get
            {
                // don't need to lock because no guarantee of instance identity
                if (httpGetBinding == null)
                {
                    httpGetBinding = CreateHttpGetBinding();
                }

                return httpGetBinding;
            }
        }

        internal static Binding Https
        {
            get
            {
                // don't need to lock because no guarantee of instance identity
                if (httpsBinding == null)
                {
                    httpsBinding = CreateHttpsBinding();
                }

                return httpsBinding;
            }
        }

        internal static Binding HttpsGet
        {
            get
            {
                // don't need to lock because no guarantee of instance identity
                if (httpsGetBinding == null)
                {
                    httpsGetBinding = CreateHttpsGetBinding();
                }

                return httpsGetBinding;
            }
        }

        internal static Binding Tcp
        {
            get
            {
                // don't need to lock because no guarantee of instance identity
                if (tcpBinding == null)
                {
                    tcpBinding = CreateTcpBinding();
                }

                return tcpBinding;
            }
        }

        internal static Binding NamedPipe
        {
            get
            {
                // don't need to lock because no guarantee of instance identity
                if (pipeBinding == null)
                {
                    pipeBinding = CreateNamedPipeBinding();
                }

                return pipeBinding;
            }
        }

        public static Binding CreateMexHttpBinding()
        {
            return MetadataExchangeBindings.CreateHttpBinding();
        }

        public static Binding CreateMexHttpsBinding()
        {
            return MetadataExchangeBindings.CreateHttpsBinding();
        }

        public static Binding CreateMexTcpBinding()
        {
            return MetadataExchangeBindings.CreateTcpBinding();
        }

        public static Binding CreateMexNamedPipeBinding()
        {
            return MetadataExchangeBindings.CreateNamedPipeBinding();
        }

        internal static Binding GetBindingForScheme(string scheme)
        {
            Binding binding = null;
            TryGetBindingForScheme(scheme, out binding);
            return binding;
        }

        internal static bool TryGetBindingForScheme(string scheme, out Binding binding)
        {
            if (String.Compare(scheme, "http", StringComparison.OrdinalIgnoreCase) == 0)
            {
                binding = Http;
            }
            else if (String.Compare(scheme, "https", StringComparison.OrdinalIgnoreCase) == 0)
            {
                binding = Https;
            }
            else if (String.Compare(scheme, "net.tcp", StringComparison.OrdinalIgnoreCase) == 0) 
            {
                binding = Tcp;
            }
            else if (String.Compare(scheme, "net.pipe", StringComparison.OrdinalIgnoreCase) == 0) 
            {
                binding = NamedPipe;
            }
            else
            {
                binding = null;
            }

            return binding != null;
        }

        static WSHttpBinding CreateHttpBinding()
        {
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.None, /* reliableSessionEnabled */ false);
            binding.Name = MetadataStrings.MetadataExchangeStrings.HttpBindingName;
            binding.Namespace = MetadataStrings.MetadataExchangeStrings.BindingNamespace;
            return binding;
        }

        static WSHttpBinding CreateHttpsBinding()
        {
            WSHttpBinding binding = new WSHttpBinding(
                new WSHttpSecurity(SecurityMode.Transport, new HttpTransportSecurity(), new NonDualMessageSecurityOverHttp()), /* reliableSessionEnabled */ false);
            binding.Name = MetadataStrings.MetadataExchangeStrings.HttpsBindingName;
            binding.Namespace = MetadataStrings.MetadataExchangeStrings.BindingNamespace;
            
            return binding;
        }

        static CustomBinding CreateHttpGetBinding()
        {
            return CreateGetBinding(new HttpTransportBindingElement());
        }

        static CustomBinding CreateHttpsGetBinding()
        {
            return CreateGetBinding(new HttpsTransportBindingElement());
        }

        static CustomBinding CreateGetBinding(HttpTransportBindingElement httpTransport)
        {
            TextMessageEncodingBindingElement textEncoding = new TextMessageEncodingBindingElement();
            textEncoding.MessageVersion = MessageVersion.None;
            httpTransport.Method = "GET";
            httpTransport.InheritBaseAddressSettings = true;
            return new CustomBinding(textEncoding, httpTransport);
        }

        static CustomBinding CreateTcpBinding()
        {
            CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.TcpBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace);
            TcpTransportBindingElement tcpTransport = new TcpTransportBindingElement();
            binding.Elements.Add(tcpTransport);
            return binding;
        }

        static CustomBinding CreateNamedPipeBinding()
        {
            CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.NamedPipeBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace);
            NamedPipeTransportBindingElement pipeTransport = new NamedPipeTransportBindingElement();
            binding.Elements.Add(pipeTransport);
            return binding;
        }

        internal static bool IsSchemeSupported(string scheme)
        {
            Binding binding;
            return TryGetBindingForScheme(scheme, out binding);
        }
    }
}