Support security mode TransportWithMessageCredential
Message level security is not currently supported. Attempting to use it will throw PlatformNotSupportedException
Currently cannot move our Windows 8.1 store application to Windows 10 because this is not implemented.
Is there any progress related with this topic, Please i need it to work in it.
Just got burned by this one too.
getting burned by lack of wsHttpBinding here now as well.
This is currently still blocked by the lack of message security feature.
I need this too!
~~This has become more pressing for us with the announcement to ASP.NET Core 2 will not target NetStandard2. We need this in to move forward!~~
They are still going to target NetStandard2, this is however what is holding us to full framework.
Any news wether this is on the short term roadmap?
Any update on the status of fixing this?
This has been an issue now for 2 and a half years, why is this basic functionality still not supported?
I ended up sidestepping WCF altogether to solve this: https://stackoverflow.com/a/48818293
I need this support!
Any official workaround, or otherwise timeline for a patch? Thanks! @Lxiamail
Normal Way
client = new MyClient(new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential), new EndpointAddress(BaseUrl));
client.ClientCredentials.UserName.UserName = UserName;
client.ClientCredentials.UserName.Password = Password;
Workaround
client = new MyClient(new BasicHttpBinding(BasicHttpSecurityMode.Transport), new EndpointAddress(BaseUrl));
client.Endpoint.SetMessageCredentials(UserName,Password);
Generates a header like:
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>user</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
Credit for solution basis: https://stackoverflow.com/questions/734355/clueless-about-how-to-create-soap-wssesecurity-header http://www.ideliverable.com/blog/calling-salesforce-soap-apis-from-a-net-core-or-uwp-app
internal class AuthenticationHeader : MessageHeader
{
public AuthenticationHeader(string UserName, string Password,bool IncludeTimestamp)
{
_UserName = UserName;
_Password = Password;
_IncludeTimestamp = IncludeTimestamp;
}
private string _UserName;
private string _Password;
private bool _IncludeTimestamp;
public override string Name => "Security";
public override string Namespace => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
protected override void OnWriteStartHeader(System.Xml.XmlDictionaryWriter writer, System.ServiceModel.Channels.MessageVersion messageVersion)
{
writer.WriteStartElement("wsse", Name, Namespace);
writer.WriteXmlnsAttribute("wsse", Namespace);
}
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
//TODO Timestamp - If Needed
writer.WriteStartElement("wsse", "UsernameToken", Namespace);
writer.WriteStartElement("wsse", "Username", Namespace);
writer.WriteValue(_UserName);
writer.WriteEndElement();
writer.WriteStartElement("wsse", "Password", Namespace);
writer.WriteValue(_Password);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
internal class AuthenticationHeaderBehavior : IEndpointBehavior
{
public AuthenticationHeaderBehavior(string UserName, string Password, bool IncludeTimestamp)
{
_UserName = UserName;
_Password = Password;
_IncludeTimestamp = IncludeTimestamp;
}
private string _UserName;
private string _Password;
private bool _IncludeTimestamp;
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.ClientMessageInspectors.Add(new AuthenticationHeaderInspector(_UserName, _Password, _IncludeTimestamp));
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
internal static class AuthenticationHeaderExtensions
{
public static void SetMessageCredentials(this ServiceEndpoint endpoint, string UserName, string Password)//, bool IncludeTimestamp)
{
//TODO Timestamp - If Needed
endpoint.EndpointBehaviors.Add(new AuthenticationHeaderBehavior(UserName, Password, false));//IncludeTimestamp));
}
}
internal class AuthenticationHeaderInspector : IClientMessageInspector
{
public AuthenticationHeaderInspector(string UserName, string Password, bool IncludeTimestamp)
{
_UserName = UserName;
_Password = Password;
_IncludeTimestamp = IncludeTimestamp;
}
private string _UserName;
private string _Password;
private bool _IncludeTimestamp;
public void AfterReceiveReply(ref Message reply, object correlationState)
{
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
request.Headers.Add(new AuthenticationHeader(_UserName, _Password, _IncludeTimestamp));
return Guid.NewGuid();
}
}
Hi @OpenSpacesAndPlaces, I try your solution with custom message Header but my result is always :
MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic Realm = 'Integration Server''.
:( I'm in .NET Core 2.1 with BasicHttpBinding and TransportCredentialsOnly Thanks you for your help
@Jhatzig
I'm not sure on your specific case - but I'd confirm you have the correct "BasicHttpSecurityMode" set.
In my build out it went from:
BasicHttpSecurityMode.TransportWithMessageCredential
to:
BasicHttpSecurityMode.Transport
Also keep in mind that not all SOAP authentication security headers are the same.
You may need to customize the XML generated by:
AuthenticationHeader : MessageHeader
The output this generates is like:
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>user</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
@OpenSpacesAndPlaces
Thanks your for your answer.
My case is :
A WS with WCF in HTTP with TransportCredentialOnly
With .NET classic, in web.config , on binding, we add the message security :
<message clientCredentialType="UserName" algorithmSuite="Default" />
but with .Net Core, we can't do that. So, I try to use your solution but it's for TransportWithMessageCredential and i'm not founding the solution for TransportCredentialOnly*
If, i'm setting to "Transport" i have the following error : ArgumentException: The provided URI scheme 'http' is invalid; expected 'https'. because my WS is in HTTP
@Jhatzig
BasicHttpSecurityMode.Transport
Or similar, is going to require an "Https" url.
You may be looking for (but I'd caution using that in anything but a development environment):
BasicHttpSecurityMode.None
As far as using the equivalent of:
TransportCredentialOnly
To my understanding, you'd need HTTP headers instead of a SOAP header - so something like this (untested) - is probably what you're after. That's kind of the direction you'll need to dig is how to add HTTP headers to a WCF requests manually.
BasicHttpSecurityMode.None
internal class AuthenticationHeaderInspector : IClientMessageInspector
{
public AuthenticationHeaderInspector(string UserName, string Password, bool IncludeTimestamp)
{
_UserName = UserName;
_Password = Password;
_IncludeTimestamp = IncludeTimestamp;
}
private string _UserName;
private string _Password;
private bool _IncludeTimestamp;
public void AfterReceiveReply(ref Message reply, object correlationState)
{
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
using (new System.ServiceModel.OperationContextScope(channel))
{
MessageHeader head = MessageHeader.CreateHeader("Authorization", "http://yournamespace.com/v1", "Basic yourcredentials");
OperationContext.Current.OutgoingMessageHeaders.Add(head);
}
return Guid.NewGuid();
}
}
Header portion sourced from: https://stackoverflow.com/questions/14621544/how-can-i-add-authorization-header-to-the-request-in-wcf
While this works, be aware that it doesn't support WS-SecureConversation which is needed for default support for WSHttpBinding. The difference when using WS-SecureConversation is a handshake happens at channel open where a secure token is negotiated and used in actual payload messages being sent back and forth. This has two advantages. First, it allows a persistent session on the server side so you can have a persistent instance context/service instance for a single client channel. Second, with more complicated tokens than username and password, the token validation can be a bit more expensive. Sending the full authentication token every time requires it to be re-validated for every request. The problem we have with in-box support is WCF depends on System.IdentityModel which the owning team don't wish to port to .NET Core. So far I've prototyped on the .NET Framework removing most of the crypto dependency of IdentityModel and I was able to get this scenario working with minimal dependency on IdentityModel (using the SignedXml implementation that's available in .NET Core instead). The next step is to bring over the WCF pieces and my prototype to .NET Core along with some pieces of IdentityModel which we will now need to own.
So in short, there are some difficult blockers but I'm working on it and have a path to get this working with a successful proof of concept prototype.
It's been three and a half years and this issue still hasn't been resolved? I too am being bit by this issue. I will try the work-arounds suggested above but it's kind of ridiculous that this has not been fixed yet.