Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix svcutil endpoint configurations generation #4843

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
68 changes: 59 additions & 9 deletions src/dotnet-svcutil/lib/src/CodeDomFixup/MethodCreationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.CodeDom;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
Expand All @@ -12,6 +11,7 @@
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using Microsoft.CodeDom;
using Microsoft.Xml;

namespace Microsoft.Tools.ServiceModel.Svcutil
Expand Down Expand Up @@ -507,10 +507,10 @@ private static void AddCustomBindingConfiguration(CodeStatementCollection statem
}
}

if(!handled)
if (!handled)
{
ReliableSessionBindingElement reliableSessionBE = bindingElement as ReliableSessionBindingElement;
if(reliableSessionBE != null)
if (reliableSessionBE != null)
{
AddReliableSessionBindingElement(statements, resultVar, reliableSessionBE);
handled = true;
Expand Down Expand Up @@ -550,15 +550,65 @@ private static void AddSslStreamSecurityBindingElement(CodeStatementCollection s
private static void AddTransportSecurityBindingElement(CodeStatementCollection statements, CodeVariableReferenceExpression customBinding, TransportSecurityBindingElement bindingElement)
{
// Security binding validation is done in EndpointSelector.cs - Add UserNameOverTransportBindingElement
TransportSecurityBindingElement defaultBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
CodeVariableDeclarationStatement userNameOverTransportSecurityBindingElement = new CodeVariableDeclarationStatement(
TransportSecurityBindingElement defaultBindingElement;
string defaultBindingElementFactoryMethodName;
CodeExpression[] defaultBindingElementFactoryMethodExpressionParameters = Array.Empty<CodeExpression>();

// CertificateOverTransport
if (SecurityBindingElement.IsCertificateOverTransportBinding(bindingElement))
{
defaultBindingElement = SecurityBindingElement.CreateCertificateOverTransportBindingElement();
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateCertificateOverTransportBindingElement);
}
// IssuedTokenOverTransport
else if (SecurityBindingElement.IsIssuedTokenOverTransportBinding(bindingElement,
out System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters issuedTokenOverTransportParameters))
{
defaultBindingElement = SecurityBindingElement.CreateIssuedTokenOverTransportBindingElement(issuedTokenOverTransportParameters);
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateIssuedTokenOverTransportBindingElement);
defaultBindingElementFactoryMethodExpressionParameters = new CodeExpression[]
{
// TODO: pass `issuedTokenOverTransportParameters` parameter
};
}
// KerberosOverTransport
else if (SecurityBindingElement.IsKerberosBinding(bindingElement))
{
defaultBindingElement = SecurityBindingElement.CreateKerberosOverTransportBindingElement();
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateKerberosOverTransportBindingElement);
}
// SspiNegotiatedOverTransport
// TODO: make `requireCancellation` out parameter ??
else if (SecurityBindingElement.IsSspiNegotiationOverTransportBinding(bindingElement, requireCancellation: true))
{
defaultBindingElement = SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement();
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement);
defaultBindingElementFactoryMethodExpressionParameters = new CodeExpression[]
{
// TODO: add requireCancellation parameter
};
}
// UserNameOverTransport
else if (SecurityBindingElement.IsUserNameOverTransportBinding(bindingElement))
{
defaultBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateUserNameOverTransportBindingElement);
}
else
{
// TODO: throw or fallback to `CreateUserNameOverTransportBindingElement` ??
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ErrBindingElementNotSupportedFormat, bindingElement.GetType()));
}

CodeVariableDeclarationStatement transportSecurityBindingElement = new CodeVariableDeclarationStatement(
typeof(TransportSecurityBindingElement),
"userNameOverTransportSecurityBindingElement",
"transportSecurityBindingElement",
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(SecurityBindingElement)),
"CreateUserNameOverTransportBindingElement"));
statements.Add(userNameOverTransportSecurityBindingElement);
CodeVariableReferenceExpression bindingElementRef = new CodeVariableReferenceExpression(userNameOverTransportSecurityBindingElement.Name);
defaultBindingElementFactoryMethodName,
defaultBindingElementFactoryMethodExpressionParameters));
statements.Add(transportSecurityBindingElement);
CodeVariableReferenceExpression bindingElementRef = new CodeVariableReferenceExpression(transportSecurityBindingElement.Name);

if (defaultBindingElement.IncludeTimestamp != bindingElement.IncludeTimestamp)
{
Expand Down