Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 54 additions & 20 deletions ClearUserPassBinding/ClearUsernameBinding.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel;
using System;
using System.ServiceModel.Channels;


Expand All @@ -15,28 +13,64 @@ namespace WebServices20.BindingExtenions
{
public class ClearUsernameBinding : CustomBinding
{
private MessageVersion messageVersion = MessageVersion.None;
private MessageVersion _messageVersion = MessageVersion.None;
private long _maxReceivedMessageSize = 65536;
private bool _allowCookies;
private bool _bypassProxyOnLocal;
private HostNameComparisonMode _hostNameComparisonMode;
private long _maxBufferPoolSize = 524288;
private bool _useDefaultWebProxy = true;
private TransferMode _transferMode;
private Uri _proxyAddress;
private bool _includeTimestamp;

public void SetMessageVersion(MessageVersion value)
{
this.messageVersion = value;
}
public void SetMessageVersion(MessageVersion value) => _messageVersion = value;

public void SetMaxReceivedMessageSize(long value) => _maxReceivedMessageSize = value;

public void SetAllowCookies(bool value) => _allowCookies = value;

public void SetBypassProxyOnLocal(bool value) => _bypassProxyOnLocal = value;

public void SetHostNameComparisonMode(HostNameComparisonMode value) => _hostNameComparisonMode = value;

public void SetMaxBufferPoolSize(long value) => _maxBufferPoolSize = value;

public void SetUseDefaultWebProxy(bool value) => _useDefaultWebProxy = value;

public void SetTransferMode(TransferMode value) => _transferMode = value;

public void SetProxyAddress(Uri value) => _proxyAddress = value;

public void SetIncludeTimestamp(bool value) => _includeTimestamp = value;

public override BindingElementCollection CreateBindingElements()
{
var res = new BindingElementCollection();
res.Add(new TextMessageEncodingBindingElement() { MessageVersion = this.messageVersion});
res.Add(SecurityBindingElement.CreateUserNameOverTransportBindingElement());
res.Add(new AutoSecuredHttpTransportElement());
return res;
}
var security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
security.IncludeTimestamp = _includeTimestamp;

public override string Scheme
{
get
var transportElement = new AutoSecuredHttpTransportElement
{
MaxReceivedMessageSize = _maxReceivedMessageSize,
AllowCookies = _allowCookies,
BypassProxyOnLocal = _bypassProxyOnLocal,
HostNameComparisonMode = _hostNameComparisonMode,
MaxBufferPoolSize = _maxBufferPoolSize,
UseDefaultWebProxy = _useDefaultWebProxy,
TransferMode = _transferMode,
ProxyAddress = _proxyAddress
};

var bindingElements = new BindingElementCollection
{
return "http";
}
new TextMessageEncodingBindingElement { MessageVersion = _messageVersion },
security,
transportElement
};

return bindingElements;
}

public override string Scheme => "http";
}
}
7 changes: 6 additions & 1 deletion ClearUserPassBinding/ClearUsernameBinding.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,11 @@
<AssemblyName>ClearUsernameBinding</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
115 changes: 89 additions & 26 deletions ClearUserPassBinding/ClearUsernameBindingElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,123 @@
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ComponentModel;
using System.ServiceModel.Configuration;
using System.Globalization;


/*
* Want more WCF tips?
* Visit http://webservices20.blogspot.com/
*/



namespace WebServices20.BindingExtenions
{
class ClearUsernameBindingElement : StandardBindingElement
internal class ClearUsernameBindingElement : StandardBindingElement
{
private ConfigurationPropertyCollection properties;
private ConfigurationPropertyCollection _properties = null;

protected override void OnApplyConfiguration(Binding binding)
{
ClearUsernameBinding b = binding as ClearUsernameBinding;
b.SetMessageVersion(MessageVersion);
}
var clearUsernameBinding = binding as ClearUsernameBinding;
clearUsernameBinding.SetMessageVersion(MessageVersion);
clearUsernameBinding.SetMaxReceivedMessageSize(Convert.ToInt64(MaxReceivedMessageSize));
clearUsernameBinding.SetAllowCookies(AllowCookies);
clearUsernameBinding.SetBypassProxyOnLocal(BypassProxyOnLocal);
clearUsernameBinding.SetHostNameComparisonMode(HostNameComparisonMode);
clearUsernameBinding.SetMaxBufferPoolSize(Convert.ToInt64(MaxBufferPoolSize));
clearUsernameBinding.SetUseDefaultWebProxy(UseDefaultWebProxy);
clearUsernameBinding.SetTransferMode(TransferMode);

protected override Type BindingElementType
{
get { return typeof(ClearUsernameBinding); }
if (!string.IsNullOrEmpty(ProxyAddress))
{
clearUsernameBinding.SetProxyAddress(new Uri(ProxyAddress));
}

clearUsernameBinding.SetIncludeTimestamp(IncludeTimestamp);
}

protected override Type BindingElementType => typeof(ClearUsernameBinding);

protected override ConfigurationPropertyCollection Properties
{
get
{
if (this.properties == null)
if (_properties == null)
{
ConfigurationPropertyCollection properties = base.Properties;
var properties = base.Properties;
properties.Add(new ConfigurationProperty("messageVersion", typeof(MessageVersion), MessageVersion.Soap11, new MessageVersionConverter(), null, ConfigurationPropertyOptions.None));
this.properties = properties;
properties.Add(new ConfigurationProperty("maxReceivedMessageSize", typeof(string), "65536"));
properties.Add(new ConfigurationProperty("allowCookies", typeof(bool), false));
properties.Add(new ConfigurationProperty("bypassProxyOnLocal", typeof(bool), false));
properties.Add(new ConfigurationProperty("maxBufferPoolSize", typeof(string), "524288"));
properties.Add(new ConfigurationProperty("useDefaultWebProxy", typeof(bool), true));
properties.Add(new ConfigurationProperty("hostNameComparisonMode", typeof(HostNameComparisonMode), HostNameComparisonMode.StrongWildcard));
properties.Add(new ConfigurationProperty("transferMode", typeof(TransferMode), TransferMode.Buffered));
properties.Add(new ConfigurationProperty("proxyAddress", typeof(string), string.Empty));
properties.Add(new ConfigurationProperty("includeTimestamp", typeof(bool), true));
_properties = properties;
}
return this.properties;
return _properties;
}
}


public string MaxReceivedMessageSize
{
get => (string)this["maxReceivedMessageSize"];
set => this["maxReceivedMessageSize"] = value;
}

public string MaxBufferPoolSize
{
get => (string)this["maxBufferPoolSize"];
set => this["maxBufferPoolSize"] = value;
}

public MessageVersion MessageVersion
{
get
{
return (MessageVersion)base["messageVersion"];
}
set
{
base["messageVersion"] = value;
}
get => (MessageVersion)this["messageVersion"];
set => this["messageVersion"] = value;
}

public bool AllowCookies
{
get => (bool)this["allowCookies"];
set => this["allowCookies"] = value;
}

public bool BypassProxyOnLocal
{
get => (bool)this["bypassProxyOnLocal"];
set => this["bypassProxyOnLocal"] = value;
}

public bool UseDefaultWebProxy
{
get => (bool)this["useDefaultWebProxy"];
set => this["useDefaultWebProxy"] = value;
}

public HostNameComparisonMode HostNameComparisonMode
{
get => (HostNameComparisonMode)this["hostNameComparisonMode"];
set => this["hostNameComparisonMode"] = value;
}

public TransferMode TransferMode
{
get => (TransferMode)this["transferMode"];
set => this["transferMode"] = value;
}

public string ProxyAddress
{
get => (string)this["proxyAddress"];
set => this["proxyAddress"] = value;
}

public bool IncludeTimestamp
{
get => (bool)this["includeTimestamp"];
set => this["includeTimestamp"] = value;
}

}
}

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
9 changes: 7 additions & 2 deletions ClearUsernameBinding.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClearUsernameBinding", "ClearUserPassBinding\ClearUsernameBinding.csproj", "{D2BC4C2B-591E-4489-9515-0075112F73B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestService", "TestService\TestService.csproj", "{7CD92A04-5F7E-4C94-9A8A-EECA5B76B1BD}"
Expand Down Expand Up @@ -63,4 +65,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EA9E3F04-EE34-458E-8121-ECC0A7BA58A0}
EndGlobalSection
EndGlobal
7 changes: 6 additions & 1 deletion MyUsernameValidator/MyUsernameValidator.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,11 @@
<AssemblyName>MyUsernameValidator</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions TestClient/Service References/ServiceReference1/Reference.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3031
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -11,20 +11,20 @@
namespace TestClient.ServiceReference1 {


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.IEchoService")]
public interface IEchoService {

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEchoService/EchoString", ReplyAction="http://tempuri.org/IEchoService/EchoStringResponse")]
string EchoString(string s);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IEchoServiceChannel : TestClient.ServiceReference1.IEchoService, System.ServiceModel.IClientChannel {
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class EchoServiceClient : System.ServiceModel.ClientBase<TestClient.ServiceReference1.IEchoService>, TestClient.ServiceReference1.IEchoService {

public EchoServiceClient() {
Expand Down
7 changes: 6 additions & 1 deletion TestClient/TestClient.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,11 @@
<AssemblyName>TestClient</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Binary file not shown.
Loading