dotnet / dotnet/wcf

SecurityBindingElement.CreateMutualCertificateDuplexBindingElement in DotNetCore

Open
#2,265 17 comments 0 reactions 0 assignees View on GitHub
Blocked
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

I am trying to use a WSDL service in dot net core that works fine in previous version of dotnet.
As I described in https://github.com/dotnet/wcf/issues/2259 and https://github.com/dotnet/wcf/issues/2258 first I tried the 'Microsoft WCF Web Service Reference Provider' Extension that result to some errors. then I tried 'SvcUtil.exe' and put generated source and config file in a DotNetFramework Console App and was able to successfully connect to the service. but as DotNetCore does not support config file I tried to turn my App.config '' section into code that finally results in this:

var binding = new CustomBinding()
{
Name = "GetCustomsPermitServiceSoapBinding",
};

var seq = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(
MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);

seq.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15;
seq.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
seq.IncludeTimestamp = true;
seq.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
seq.RequireSignatureConfirmation = false;
seq.SetKeyDerivation(requireDerivedKeys: false);
seq.LocalClientSettings.DetectReplays = true;
seq.LocalServiceSettings.DetectReplays = true;

binding.Elements.Add(seq);

binding.Elements.Add(new TextMessageEncodingBindingElement());
binding.Elements.Add(new HttpTransportBindingElement());

var endpointAddress = new EndpointAddress(new Uri("http://servicebus.ecogif.ir/IRICA/GetCustomsPermit/4"),
new DnsEndpointIdentity("servicebus.ecogif.ir"));

var client = new GetCustomsPermitClient(binding, endpointAddress);
client.ClientCredentials.ClientCertificate.SetCertificate(storeLocation: StoreLocation.LocalMachine, storeName: StoreName.My, findType: X509FindType.FindBySubjectName,
findValue: "tamliki.ir");
client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(storeLocation: StoreLocation.LocalMachine, storeName: StoreName.TrustedPeople, findType: X509FindType.FindBySubjectName,
findValue: "servicebus.ecogif.ir");

var pate = client.getCustomsPermitByCustomsPermitNumber("20306133132", "1");`

And It works properly

then I copied this code into a DotNetCore Console App but it seems somethings must be changed as there is no "CreateMutualCertificateDuplexBindingElement" and no "SecurityAlgorithmSuite"

What is the equivalent of this code in DotNetCore?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.