question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core 3.1 X509 signature

See original GitHub issue

I’m having a problem with signing WCF calls with a X509 certificate signature.

The following code works with .NET Framework but it doesn’t with .NET Core because X509SecurityToken doesn’t exist and I can’t access the RequestSoapContext.

SvcService.Service ws = new SvcService.Service();
X509Certificate2 cert = new X509Certificate2("cert.pfx", 
"privatekeypassword");
X509SecurityToken token = new X509SecurityToken(cert);
 ws.RequestSoapContext.Security.Tokens.Add(token);
 ws.RequestSoapContext.Security.Elements.Add(new MessageSignature(token));
 
 DataSet ds = ws.GetItem(2081234);

What would be the method to achieve the same in .NET Core? The proxy classes are generated with dotnet-svcutil.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mconnewcommented, Oct 6, 2020

The content type application/soap+xml is for SOAP 1.2 and text/xml is for SOAP 1.1. So your service is returning a SOAP 1.2 response. You can either modify your binding or create a new binding and setting the appropriate message version on the TextMessageEncodingBindingElement. I suspect the following binding should work for you:

var mebe = new TextMessageEncodingBindingElement();
mebe.MessageVersion = MessageVersion.Soap12;
var transportbe = new HttpTransportBindingElement();
var binding = new CustomBinding(mebe, transportbe);

If not, then use:

var customBinding = new CustomBinding(existingBinding);
var mebe = customBinding.Elements.Find<TextMessageEncodingBindingElement>();
mebe.MessageVersion = MessageVersion.Soap12;

And use the customBinding when creating your channel factory.

0reactions
domagojmedocommented, Oct 12, 2022

@mconnew is there any plan to enable this signing on .NET Core? I see that you commented that you would like to include it, but issue has since been closed

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to properly validate X.509 certificates in C# with .NET ...
Build() should not be trusted on its own; proper certificate verification requires one manually and separately perform verification of correct ...
Read more >
X509SignatureGenerator Class (System.Security. ...
Base class for building encoded signatures as needed for X.509 certificates. ... NET, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1,...
Read more >
Using an X509 private key to sign data in dotnet core v2 ...
The dotnet core signed data fails a signature verification check in the .NET 4.5 codebase. Theoretically it should make no difference what the ......
Read more >
Certificate Authentication in ASP.NET Core 3.1
In this example, a shared self signed certificate is used to authenticate one application calling an API on a second ASP.NET Core application....
Read more >
How to Use Certificates in ASP.NET Core
In this article, we will learn about certificates and why we need them. We will also see how to create a self-signed certificate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found