diff --git a/src/dotnet-svcutil/lib/src/CodeDomFixup/MethodCreationHelper.cs b/src/dotnet-svcutil/lib/src/CodeDomFixup/MethodCreationHelper.cs index 9cfa4aaaad6..0c774573051 100644 --- a/src/dotnet-svcutil/lib/src/CodeDomFixup/MethodCreationHelper.cs +++ b/src/dotnet-svcutil/lib/src/CodeDomFixup/MethodCreationHelper.cs @@ -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; @@ -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 @@ -1115,16 +1115,106 @@ private static void AddWinStreamSecurityBindingElement(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(); + + // 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); + + statements.Add(new CodeVariableDeclarationStatement( + issuedTokenOverTransportParameters.IssuerBinding.GetType(), + "issuerBinding", + new CodeObjectCreateExpression(issuedTokenOverTransportParameters.IssuerBinding.GetType()))); + + statements.Add(new CodeVariableDeclarationStatement( + typeof(EndpointAddress), + "issuerAddress", + new CodeObjectCreateExpression(typeof(EndpointAddress), + new CodeObjectCreateExpression(typeof(Uri), + new CodePrimitiveExpression(issuedTokenOverTransportParameters.IssuerAddress.ToString()))))); + + statements.Add(new CodeVariableDeclarationStatement( + typeof(System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters), + "issuedTokenParameters", + new CodeObjectCreateExpression( + typeof(System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters), + new CodeExpression[] + { + new CodePrimitiveExpression(issuedTokenOverTransportParameters.TokenType), + new CodeVariableReferenceExpression("issuerAddress"), + new CodeVariableReferenceExpression("issuerBinding") + }))); + + statements.Add(new CodeAssignStatement( + new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("issuedTokenParameters"), "KeySize"), + new CodePrimitiveExpression(issuedTokenOverTransportParameters.KeySize))); + + statements.Add(new CodeAssignStatement( + new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("issuedTokenParameters"), "UseStrTransform"), + new CodePrimitiveExpression(issuedTokenOverTransportParameters.UseStrTransform))); + + + defaultBindingElementFactoryMethodExpressionParameters = new CodeExpression[] + { + new CodeVariableReferenceExpression("issuedTokenParameters") + }; + } + + // KerberosOverTransport + else if (SecurityBindingElement.IsKerberosBinding(bindingElement)) + { + defaultBindingElement = SecurityBindingElement.CreateKerberosOverTransportBindingElement(); + defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateKerberosOverTransportBindingElement); + } + + // SspiNegotiatedOverTransport + else if (SecurityBindingElement.IsSspiNegotiationOverTransportBinding(bindingElement, requireCancellation: true)) + { + defaultBindingElement = SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(); + defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement); + } + else if (SecurityBindingElement.IsSspiNegotiationOverTransportBinding(bindingElement, requireCancellation: false)) + { + defaultBindingElement = SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(false); + defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement); + defaultBindingElementFactoryMethodExpressionParameters = new CodeExpression[] + { + new CodePrimitiveExpression(false) + }; + } + + // UserNameOverTransport + else if (SecurityBindingElement.IsUserNameOverTransportBinding(bindingElement)) + { + defaultBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); + defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateUserNameOverTransportBindingElement); + } + else + { + 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) { @@ -1386,6 +1476,19 @@ private static void AddHttpBindingElement(CodeStatementCollection statements, Co "MaxReceivedMessageSize"), new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(typeof(int)), "MaxValue"))); + if (isHttps) + { + var defaultHttpsBindingElement = defaultBindingElement as HttpsTransportBindingElement; + var httpsBindingElement = bindingElement as HttpsTransportBindingElement; + if (defaultHttpsBindingElement.RequireClientCertificate != httpsBindingElement.RequireClientCertificate) + { + statements.Add( + new CodeAssignStatement( + new CodePropertyReferenceExpression(bindingElementRef, "RequireClientCertificate"), + new CodePrimitiveExpression(httpsBindingElement.RequireClientCertificate))); + } + } + if (defaultBindingElement.TransferMode != bindingElement.TransferMode) { statements.Add( diff --git a/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/CertificateAuth/Reference.cs b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/CertificateAuth/Reference.cs new file mode 100644 index 00000000000..992d0d947a3 --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/CertificateAuth/Reference.cs @@ -0,0 +1,134 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CertificateAuth_NS +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + [System.ServiceModel.ServiceContractAttribute(ConfigurationName="CertificateAuth_NS.IService")] + public interface IService + { + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/GetMessage", ReplyAction="http://tempuri.org/IService/GetMessageResponse")] + System.Threading.Tasks.Task GetMessageAsync(); + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + public interface IServiceChannel : CertificateAuth_NS.IService, System.ServiceModel.IClientChannel + { + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + public partial class ServiceClient : System.ServiceModel.ClientBase, CertificateAuth_NS.IService + { + + /// + /// Implement this partial method to configure the service endpoint. + /// + /// The endpoint to configure + /// The client credentials + static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); + + public ServiceClient(EndpointConfiguration endpointConfiguration) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), ServiceClient.GetEndpointAddress(endpointConfiguration)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : + base(binding, remoteAddress) + { + } + + public System.Threading.Tasks.Task GetMessageAsync() + { + return base.Channel.GetMessageAsync(); + } + + public virtual System.Threading.Tasks.Task OpenAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndOpen)); + } + + #if !NET6_0_OR_GREATER + public virtual System.Threading.Tasks.Task CloseAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndClose)); + } + #endif + + private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IService)) + { + System.ServiceModel.WSHttpBinding result = new System.ServiceModel.WSHttpBinding(); + result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; + result.MaxReceivedMessageSize = int.MaxValue; + result.AllowCookies = true; + result.Security.Mode = System.ServiceModel.SecurityMode.Transport; + result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Certificate; + return result; + } + if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService)) + { + System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding(); + System.ServiceModel.Channels.TransportSecurityBindingElement transportSecurityBindingElement = System.ServiceModel.Channels.SecurityBindingElement.CreateCertificateOverTransportBindingElement(); + transportSecurityBindingElement.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; + result.Elements.Add(transportSecurityBindingElement); + result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement()); + System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement(); + httpsBindingElement.AllowCookies = true; + httpsBindingElement.MaxBufferSize = int.MaxValue; + httpsBindingElement.MaxReceivedMessageSize = int.MaxValue; + httpsBindingElement.RequireClientCertificate = true; + result.Elements.Add(httpsBindingElement); + return result; + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IService)) + { + return new System.ServiceModel.EndpointAddress(new System.Uri("https://contoso.com:8123/Service"), new System.ServiceModel.DnsEndpointIdentity("Contoso.com")); + } + if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService)) + { + return new System.ServiceModel.EndpointAddress(new System.Uri("https://contoso.com:8123/Service/custom"), new System.ServiceModel.DnsEndpointIdentity("Contoso.com")); + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + public enum EndpointConfiguration + { + + WSHttpBinding_IService, + + CustomBinding_IService, + } + } +} \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/CertificateAuth/dotnet-svcutil.params.json b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/CertificateAuth/dotnet-svcutil.params.json new file mode 100644 index 00000000000..738b7a4fe17 --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/CertificateAuth/dotnet-svcutil.params.json @@ -0,0 +1,15 @@ +{ + "providerId": "Microsoft.Tools.ServiceModel.Svcutil", + "version": "99.99.99", + "options": { + "inputs": [ + "../../../../../src/dotnet-svcutil/lib/tests/TestCases/wsdl/CertificateAuth.wsdl" + ], + "namespaceMappings": [ + "*, CertificateAuth_NS" + ], + "outputFile": "Reference.cs", + "targetFramework": "N.N", + "typeReuseMode": "None" + } +} \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenFasle/Reference.cs b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenFasle/Reference.cs new file mode 100644 index 00000000000..cf514e75e79 --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenFasle/Reference.cs @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SspiNegoAuthRequireCancelTokenFasle_NS +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + [System.ServiceModel.ServiceContractAttribute(ConfigurationName="SspiNegoAuthRequireCancelTokenFasle_NS.IService")] + public interface IService + { + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/GetData", ReplyAction="http://tempuri.org/IService/GetDataResponse")] + System.Threading.Tasks.Task GetDataAsync(int value); + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + public interface IServiceChannel : SspiNegoAuthRequireCancelTokenFasle_NS.IService, System.ServiceModel.IClientChannel + { + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + public partial class ServiceClient : System.ServiceModel.ClientBase, SspiNegoAuthRequireCancelTokenFasle_NS.IService + { + + /// + /// Implement this partial method to configure the service endpoint. + /// + /// The endpoint to configure + /// The client credentials + static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); + + public ServiceClient() : + base(ServiceClient.GetDefaultBinding(), ServiceClient.GetDefaultEndpointAddress()) + { + this.Endpoint.Name = EndpointConfiguration.CustomBinding_IService.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), ServiceClient.GetEndpointAddress(endpointConfiguration)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : + base(binding, remoteAddress) + { + } + + public System.Threading.Tasks.Task GetDataAsync(int value) + { + return base.Channel.GetDataAsync(value); + } + + public virtual System.Threading.Tasks.Task OpenAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndOpen)); + } + + #if !NET6_0_OR_GREATER + public virtual System.Threading.Tasks.Task CloseAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndClose)); + } + #endif + + private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService)) + { + System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding(); + System.ServiceModel.Channels.TransportSecurityBindingElement transportSecurityBindingElement = System.ServiceModel.Channels.SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(false); + transportSecurityBindingElement.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; + result.Elements.Add(transportSecurityBindingElement); + System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement(); + textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap11, System.ServiceModel.Channels.AddressingVersion.WSAddressing10); + result.Elements.Add(textBindingElement); + result.Elements.Add(new System.ServiceModel.Channels.WindowsStreamSecurityBindingElement()); + System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement(); + tcpBindingElement.MaxBufferSize = int.MaxValue; + tcpBindingElement.TransferMode = System.ServiceModel.TransferMode.Streamed; + tcpBindingElement.MaxReceivedMessageSize = int.MaxValue; + result.Elements.Add(tcpBindingElement); + return result; + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService)) + { + return new System.ServiceModel.EndpointAddress("net.tcp://localhost:8189/Service"); + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.Channels.Binding GetDefaultBinding() + { + return ServiceClient.GetBindingForEndpoint(EndpointConfiguration.CustomBinding_IService); + } + + private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress() + { + return ServiceClient.GetEndpointAddress(EndpointConfiguration.CustomBinding_IService); + } + + public enum EndpointConfiguration + { + + CustomBinding_IService, + } + } +} \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenFasle/dotnet-svcutil.params.json b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenFasle/dotnet-svcutil.params.json new file mode 100644 index 00000000000..e5db29e319f --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenFasle/dotnet-svcutil.params.json @@ -0,0 +1,15 @@ +{ + "providerId": "Microsoft.Tools.ServiceModel.Svcutil", + "version": "99.99.99", + "options": { + "inputs": [ + "../../../../../src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenFasle.wsdl" + ], + "namespaceMappings": [ + "*, SspiNegoAuthRequireCancelTokenFasle_NS" + ], + "outputFile": "Reference.cs", + "targetFramework": "N.N", + "typeReuseMode": "None" + } +} \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenTrue/Reference.cs b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenTrue/Reference.cs new file mode 100644 index 00000000000..e28d8f29d09 --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenTrue/Reference.cs @@ -0,0 +1,137 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SspiNegoAuthRequireCancelTokenTrue_NS +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + [System.ServiceModel.ServiceContractAttribute(ConfigurationName="SspiNegoAuthRequireCancelTokenTrue_NS.IService")] + public interface IService + { + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/GetData", ReplyAction="http://tempuri.org/IService/GetDataResponse")] + System.Threading.Tasks.Task GetDataAsync(int value); + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + public interface IServiceChannel : SspiNegoAuthRequireCancelTokenTrue_NS.IService, System.ServiceModel.IClientChannel + { + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")] + public partial class ServiceClient : System.ServiceModel.ClientBase, SspiNegoAuthRequireCancelTokenTrue_NS.IService + { + + /// + /// Implement this partial method to configure the service endpoint. + /// + /// The endpoint to configure + /// The client credentials + static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); + + public ServiceClient() : + base(ServiceClient.GetDefaultBinding(), ServiceClient.GetDefaultEndpointAddress()) + { + this.Endpoint.Name = EndpointConfiguration.CustomBinding_IService.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), ServiceClient.GetEndpointAddress(endpointConfiguration)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : + base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : + base(binding, remoteAddress) + { + } + + public System.Threading.Tasks.Task GetDataAsync(int value) + { + return base.Channel.GetDataAsync(value); + } + + public virtual System.Threading.Tasks.Task OpenAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndOpen)); + } + + #if !NET6_0_OR_GREATER + public virtual System.Threading.Tasks.Task CloseAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndClose)); + } + #endif + + private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService)) + { + System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding(); + System.ServiceModel.Channels.TransportSecurityBindingElement transportSecurityBindingElement = System.ServiceModel.Channels.SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(); + transportSecurityBindingElement.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; + result.Elements.Add(transportSecurityBindingElement); + System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement(); + textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap11, System.ServiceModel.Channels.AddressingVersion.WSAddressing10); + result.Elements.Add(textBindingElement); + result.Elements.Add(new System.ServiceModel.Channels.WindowsStreamSecurityBindingElement()); + System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement(); + tcpBindingElement.MaxBufferSize = int.MaxValue; + tcpBindingElement.TransferMode = System.ServiceModel.TransferMode.Streamed; + tcpBindingElement.MaxReceivedMessageSize = int.MaxValue; + result.Elements.Add(tcpBindingElement); + return result; + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService)) + { + return new System.ServiceModel.EndpointAddress("net.tcp://localhost:8189/Service"); + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.Channels.Binding GetDefaultBinding() + { + return ServiceClient.GetBindingForEndpoint(EndpointConfiguration.CustomBinding_IService); + } + + private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress() + { + return ServiceClient.GetEndpointAddress(EndpointConfiguration.CustomBinding_IService); + } + + public enum EndpointConfiguration + { + + CustomBinding_IService, + } + } +} \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenTrue/dotnet-svcutil.params.json b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenTrue/dotnet-svcutil.params.json new file mode 100644 index 00000000000..9e0ea08d6dd --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/Baselines/CustomBindingSecurityCodeGenTest/SspiNegoAuthRequireCancelTokenTrue/dotnet-svcutil.params.json @@ -0,0 +1,15 @@ +{ + "providerId": "Microsoft.Tools.ServiceModel.Svcutil", + "version": "99.99.99", + "options": { + "inputs": [ + "../../../../../src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenTrue.wsdl" + ], + "namespaceMappings": [ + "*, SspiNegoAuthRequireCancelTokenTrue_NS" + ], + "outputFile": "Reference.cs", + "targetFramework": "N.N", + "typeReuseMode": "None" + } +} \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/TestCases/wsdl/CertificateAuth.wsdl b/src/dotnet-svcutil/lib/tests/TestCases/wsdl/CertificateAuth.wsdl new file mode 100644 index 00000000000..c70803a70d6 --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/TestCases/wsdl/CertificateAuth.wsdl @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +https://Contoso.com:8123/Service + +Contoso.com + + + + + + +https://Contoso.com:8123/Service/custom + +Contoso.com + + + + + \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenFasle.wsdl b/src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenFasle.wsdl new file mode 100644 index 00000000000..1d67fd5f86b --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenFasle.wsdl @@ -0,0 +1,146 @@ + + + + + + + + + +EncryptAndSign + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +net.tcp://localhost:8189/Service + +v-carwan@fareast.corp.microsoft.com + + + + + \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenTrue.wsdl b/src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenTrue.wsdl new file mode 100644 index 00000000000..9fe87617513 --- /dev/null +++ b/src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenTrue.wsdl @@ -0,0 +1,144 @@ + + + + + + + + + +EncryptAndSign + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +net.tcp://localhost:8189/Service + +v-carwan@fareast.corp.microsoft.com + + + + + \ No newline at end of file diff --git a/src/dotnet-svcutil/lib/tests/src/E2ETests.cs b/src/dotnet-svcutil/lib/tests/src/E2ETests.cs index 57be8d0d5c7..c006bf01417 100644 --- a/src/dotnet-svcutil/lib/tests/src/E2ETests.cs +++ b/src/dotnet-svcutil/lib/tests/src/E2ETests.cs @@ -522,6 +522,25 @@ private void WcfRuntimeSvcs(string serviceName, bool expectSuccess) this_TestCaseName = testCaseName; TestSvcutil(AppendCommonOptions(uri), expectSuccess); } + + [Trait("Category", "Test")] + [Theory] + [InlineData("CertificateAuth")] + [InlineData("SspiNegoAuthRequireCancelTokenFasle")] + [InlineData("SspiNegoAuthRequireCancelTokenTrue")] + public void CustomBindingSecurityCodeGenTest(string testCaseName) + { + this_TestCaseName = "CustomBindingSecurityCodeGenTest"; + TestFixture(); + InitializeE2E(testCaseName); + + string wsdlFile = Path.Combine(g_TestCasesDir, "wsdl", $"{testCaseName}.wsdl"); + Assert.True(File.Exists(wsdlFile), $"{wsdlFile} not initialized!"); + + this_TestCaseName = testCaseName; + TestSvcutil(AppendCommonOptions(wsdlFile)); + } + /* // TODO: // this is not an actual test but it is a way to keep the repo clean of dead-baselines.