-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClearUsernameBinding.cs
73 lines (64 loc) · 2.32 KB
/
ClearUsernameBinding.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
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;
/*
* Want more WCF tips?
* Visit http://webservices20.blogspot.com/
* http://webservices20.blogspot.ca/2008/11/introducing-wcf-clearusernamebinding.html
*/
namespace WebServices20.BindingExtenions
{
public class ClearUsernameBinding : CustomBinding
{
private MessageVersion messageVersion = MessageVersion.None;
private bool enableUnsecuredResponse = false;
private bool includeTimeStamp = true;
public void SetMessageVersion(MessageVersion value)
{
this.messageVersion = value;
}
public void SetEnableUnsecuredResponse(bool value)
{
this.enableUnsecuredResponse = value;
}
public void SetIncludeTimeStamp(bool value)
{
this.includeTimeStamp = value;
}
/// <summary>
/// Support for configurable security parameters in binding. Changed default reader quotas and message size limits
/// </summary>
/// <returns></returns>
public override BindingElementCollection CreateBindingElements()
{
var res = new BindingElementCollection();
XmlDictionaryReaderQuotas rqMax = XmlDictionaryReaderQuotas.Max;
TextMessageEncodingBindingElement tb = new TextMessageEncodingBindingElement()
{
MessageVersion = this.messageVersion
};
rqMax.CopyTo(tb.ReaderQuotas);
res.Add(tb);
TransportSecurityBindingElement security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
security.IncludeTimestamp = this.includeTimeStamp;
if (this.enableUnsecuredResponse)
{
security.EnableUnsecuredResponse = true;
security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
}
res.Add(security);
res.Add(new AutoSecuredHttpTransportElement());
return res;
}
public override string Scheme
{
get
{
return "http";
}
}
}
}