/
BasicHttpBinding.cs
102 lines (85 loc) · 3.5 KB
/
BasicHttpBinding.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ServiceModel.Channels;
namespace System.ServiceModel
{
public class BasicHttpBinding : HttpBindingBase
{
private WSMessageEncoding _messageEncoding = BasicHttpBindingDefaults.MessageEncoding;
private BasicHttpSecurity _basicHttpSecurity;
public BasicHttpBinding() : this(BasicHttpSecurityMode.None) { }
public BasicHttpBinding(BasicHttpSecurityMode securityMode)
: base()
{
if (securityMode == BasicHttpSecurityMode.Message ||
securityMode == BasicHttpSecurityMode.TransportWithMessageCredential)
{
throw ExceptionHelper.PlatformNotSupported(SR.Format(SR.UnsupportedSecuritySetting, "securityMode", securityMode));
}
Initialize();
_basicHttpSecurity.Mode = securityMode;
}
internal WSMessageEncoding MessageEncoding
{
get { return _messageEncoding; }
set { _messageEncoding = value; }
}
public BasicHttpSecurity Security
{
get { return _basicHttpSecurity; }
set
{
if (value == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
_basicHttpSecurity = value;
}
}
internal override BasicHttpSecurity BasicHttpSecurity
{
get
{
return _basicHttpSecurity;
}
}
internal override EnvelopeVersion GetEnvelopeVersion()
{
return EnvelopeVersion.Soap11;
}
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingParameterCollection parameters)
{
if ((BasicHttpSecurity.Mode == BasicHttpSecurityMode.Transport ||
BasicHttpSecurity.Mode == BasicHttpSecurityMode.TransportCredentialOnly) &&
BasicHttpSecurity.Transport.ClientCredentialType == HttpClientCredentialType.InheritedFromHost)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.HttpClientCredentialTypeInvalid, BasicHttpSecurity.Transport.ClientCredentialType)));
}
return base.BuildChannelFactory<TChannel>(parameters);
}
public override BindingElementCollection CreateBindingElements()
{
CheckSettings();
// return collection of BindingElements
BindingElementCollection bindingElements = new BindingElementCollection();
// order of BindingElements is important
// add security (*optional)
SecurityBindingElement wsSecurity = BasicHttpSecurity.CreateMessageSecurity();
if (wsSecurity != null)
{
bindingElements.Add(wsSecurity);
}
// add encoding
if (MessageEncoding == WSMessageEncoding.Text)
bindingElements.Add(TextMessageEncodingBindingElement);
// add transport (http or https)
bindingElements.Add(GetTransport());
return bindingElements.Clone();
}
private void Initialize()
{
_basicHttpSecurity = new BasicHttpSecurity();
}
}
}