Skip to content

Commit ab5f4f2

Browse files
committed
Add test.
1 parent 9102754 commit ab5f4f2

File tree

11 files changed

+960
-8
lines changed

11 files changed

+960
-8
lines changed

src/dotnet-svcutil/lib/src/CodeDomFixup/MethodCreationHelper.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,12 +1120,12 @@ private static void AddTransportSecurityBindingElement(CodeStatementCollection s
11201120
CodeExpression[] defaultBindingElementFactoryMethodExpressionParameters = Array.Empty<CodeExpression>();
11211121

11221122
// CertificateOverTransport
1123-
// [carol] Validated: correctly generates code
11241123
if (SecurityBindingElement.IsCertificateOverTransportBinding(bindingElement))
11251124
{
11261125
defaultBindingElement = SecurityBindingElement.CreateCertificateOverTransportBindingElement();
11271126
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateCertificateOverTransportBindingElement);
11281127
}
1128+
11291129
// IssuedTokenOverTransport
11301130
else if (SecurityBindingElement.IsIssuedTokenOverTransportBinding(bindingElement,
11311131
out System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters issuedTokenOverTransportParameters))
@@ -1147,8 +1147,6 @@ private static void AddTransportSecurityBindingElement(CodeStatementCollection s
11471147

11481148
defaultBindingElementFactoryMethodExpressionParameters = new CodeExpression[]
11491149
{
1150-
// [carol] Updated this TODO item - need review to confirm
1151-
// TODO: pass `issuedTokenOverTransportParameters` parameter
11521150
new CodeObjectCreateExpression(
11531151
typeof(System.ServiceModel.Security.Tokens.IssuedSecurityTokenParameters),
11541152
new CodeExpression[]
@@ -1166,9 +1164,8 @@ private static void AddTransportSecurityBindingElement(CodeStatementCollection s
11661164
defaultBindingElement = SecurityBindingElement.CreateKerberosOverTransportBindingElement();
11671165
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateKerberosOverTransportBindingElement);
11681166
}
1167+
11691168
// SspiNegotiatedOverTransport
1170-
// [carol] Updated implementation: Whether the requireCancellation parameter is needed depends on the outcome of the method call in the following if-statements.
1171-
// TODO: make `requireCancellation` out parameter ??
11721169
else if (SecurityBindingElement.IsSspiNegotiationOverTransportBinding(bindingElement, requireCancellation: true))
11731170
{
11741171
defaultBindingElement = SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement();
@@ -1180,8 +1177,6 @@ private static void AddTransportSecurityBindingElement(CodeStatementCollection s
11801177
defaultBindingElementFactoryMethodName = nameof(SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement);
11811178
defaultBindingElementFactoryMethodExpressionParameters = new CodeExpression[]
11821179
{
1183-
// [carol] Updated: The requireCancellation parameter is only necessary when setting it to false. In the parameterless constructor, requireCancellation defaults to true.
1184-
// TODO: add requireCancellation parameter
11851180
new CodePrimitiveExpression(false)
11861181
};
11871182
}
@@ -1194,7 +1189,6 @@ private static void AddTransportSecurityBindingElement(CodeStatementCollection s
11941189
}
11951190
else
11961191
{
1197-
// TODO: throw or fallback to `CreateUserNameOverTransportBindingElement` ??
11981192
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ErrBindingElementNotSupportedFormat, bindingElement.GetType()));
11991193
}
12001194

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace CertificateAuth_NS
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
15+
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="CertificateAuth_NS.IService")]
16+
public interface IService
17+
{
18+
19+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/GetMessage", ReplyAction="http://tempuri.org/IService/GetMessageResponse")]
20+
System.Threading.Tasks.Task<string> GetMessageAsync();
21+
}
22+
23+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
24+
public interface IServiceChannel : CertificateAuth_NS.IService, System.ServiceModel.IClientChannel
25+
{
26+
}
27+
28+
[System.Diagnostics.DebuggerStepThroughAttribute()]
29+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
30+
public partial class ServiceClient : System.ServiceModel.ClientBase<CertificateAuth_NS.IService>, CertificateAuth_NS.IService
31+
{
32+
33+
/// <summary>
34+
/// Implement this partial method to configure the service endpoint.
35+
/// </summary>
36+
/// <param name="serviceEndpoint">The endpoint to configure</param>
37+
/// <param name="clientCredentials">The client credentials</param>
38+
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
39+
40+
public ServiceClient(EndpointConfiguration endpointConfiguration) :
41+
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), ServiceClient.GetEndpointAddress(endpointConfiguration))
42+
{
43+
this.Endpoint.Name = endpointConfiguration.ToString();
44+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
45+
}
46+
47+
public ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
48+
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
49+
{
50+
this.Endpoint.Name = endpointConfiguration.ToString();
51+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
52+
}
53+
54+
public ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
55+
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
56+
{
57+
this.Endpoint.Name = endpointConfiguration.ToString();
58+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
59+
}
60+
61+
public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
62+
base(binding, remoteAddress)
63+
{
64+
}
65+
66+
public System.Threading.Tasks.Task<string> GetMessageAsync()
67+
{
68+
return base.Channel.GetMessageAsync();
69+
}
70+
71+
public virtual System.Threading.Tasks.Task OpenAsync()
72+
{
73+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
74+
}
75+
76+
#if !NET6_0_OR_GREATER
77+
public virtual System.Threading.Tasks.Task CloseAsync()
78+
{
79+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
80+
}
81+
#endif
82+
83+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
84+
{
85+
if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IService))
86+
{
87+
System.ServiceModel.WSHttpBinding result = new System.ServiceModel.WSHttpBinding();
88+
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
89+
result.MaxReceivedMessageSize = int.MaxValue;
90+
result.AllowCookies = true;
91+
result.Security.Mode = System.ServiceModel.SecurityMode.Transport;
92+
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Certificate;
93+
return result;
94+
}
95+
if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService))
96+
{
97+
System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
98+
System.ServiceModel.Channels.TransportSecurityBindingElement transportSecurityBindingElement = System.ServiceModel.Channels.SecurityBindingElement.CreateCertificateOverTransportBindingElement();
99+
transportSecurityBindingElement.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
100+
result.Elements.Add(transportSecurityBindingElement);
101+
result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
102+
System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
103+
httpsBindingElement.AllowCookies = true;
104+
httpsBindingElement.MaxBufferSize = int.MaxValue;
105+
httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
106+
httpsBindingElement.RequireClientCertificate = true;
107+
result.Elements.Add(httpsBindingElement);
108+
return result;
109+
}
110+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
111+
}
112+
113+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
114+
{
115+
if ((endpointConfiguration == EndpointConfiguration.WSHttpBinding_IService))
116+
{
117+
return new System.ServiceModel.EndpointAddress(new System.Uri("https://contoso.com:8123/Service"), new System.ServiceModel.DnsEndpointIdentity("Contoso.com"));
118+
}
119+
if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService))
120+
{
121+
return new System.ServiceModel.EndpointAddress(new System.Uri("https://contoso.com:8123/Service/custom"), new System.ServiceModel.DnsEndpointIdentity("Contoso.com"));
122+
}
123+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
124+
}
125+
126+
public enum EndpointConfiguration
127+
{
128+
129+
WSHttpBinding_IService,
130+
131+
CustomBinding_IService,
132+
}
133+
}
134+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
3+
"version": "99.99.99",
4+
"options": {
5+
"inputs": [
6+
"../../../../../src/dotnet-svcutil/lib/tests/TestCases/wsdl/CertificateAuth.wsdl"
7+
],
8+
"namespaceMappings": [
9+
"*, CertificateAuth_NS"
10+
],
11+
"outputFile": "Reference.cs",
12+
"targetFramework": "N.N",
13+
"typeReuseMode": "None"
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
namespace SspiNegoAuthRequireCancelTokenFasle_NS
11+
{
12+
13+
14+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
15+
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="SspiNegoAuthRequireCancelTokenFasle_NS.IService")]
16+
public interface IService
17+
{
18+
19+
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/GetData", ReplyAction="http://tempuri.org/IService/GetDataResponse")]
20+
System.Threading.Tasks.Task<string> GetDataAsync(int value);
21+
}
22+
23+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
24+
public interface IServiceChannel : SspiNegoAuthRequireCancelTokenFasle_NS.IService, System.ServiceModel.IClientChannel
25+
{
26+
}
27+
28+
[System.Diagnostics.DebuggerStepThroughAttribute()]
29+
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
30+
public partial class ServiceClient : System.ServiceModel.ClientBase<SspiNegoAuthRequireCancelTokenFasle_NS.IService>, SspiNegoAuthRequireCancelTokenFasle_NS.IService
31+
{
32+
33+
/// <summary>
34+
/// Implement this partial method to configure the service endpoint.
35+
/// </summary>
36+
/// <param name="serviceEndpoint">The endpoint to configure</param>
37+
/// <param name="clientCredentials">The client credentials</param>
38+
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
39+
40+
public ServiceClient() :
41+
base(ServiceClient.GetDefaultBinding(), ServiceClient.GetDefaultEndpointAddress())
42+
{
43+
this.Endpoint.Name = EndpointConfiguration.CustomBinding_IService.ToString();
44+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
45+
}
46+
47+
public ServiceClient(EndpointConfiguration endpointConfiguration) :
48+
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), ServiceClient.GetEndpointAddress(endpointConfiguration))
49+
{
50+
this.Endpoint.Name = endpointConfiguration.ToString();
51+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
52+
}
53+
54+
public ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
55+
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
56+
{
57+
this.Endpoint.Name = endpointConfiguration.ToString();
58+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
59+
}
60+
61+
public ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
62+
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
63+
{
64+
this.Endpoint.Name = endpointConfiguration.ToString();
65+
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
66+
}
67+
68+
public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
69+
base(binding, remoteAddress)
70+
{
71+
}
72+
73+
public System.Threading.Tasks.Task<string> GetDataAsync(int value)
74+
{
75+
return base.Channel.GetDataAsync(value);
76+
}
77+
78+
public virtual System.Threading.Tasks.Task OpenAsync()
79+
{
80+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
81+
}
82+
83+
#if !NET6_0_OR_GREATER
84+
public virtual System.Threading.Tasks.Task CloseAsync()
85+
{
86+
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
87+
}
88+
#endif
89+
90+
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
91+
{
92+
if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService))
93+
{
94+
System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
95+
System.ServiceModel.Channels.TransportSecurityBindingElement transportSecurityBindingElement = System.ServiceModel.Channels.SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(false);
96+
transportSecurityBindingElement.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
97+
result.Elements.Add(transportSecurityBindingElement);
98+
System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
99+
textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap11, System.ServiceModel.Channels.AddressingVersion.WSAddressing10);
100+
result.Elements.Add(textBindingElement);
101+
result.Elements.Add(new System.ServiceModel.Channels.WindowsStreamSecurityBindingElement());
102+
System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement();
103+
tcpBindingElement.MaxBufferSize = int.MaxValue;
104+
tcpBindingElement.TransferMode = System.ServiceModel.TransferMode.Streamed;
105+
tcpBindingElement.MaxReceivedMessageSize = int.MaxValue;
106+
result.Elements.Add(tcpBindingElement);
107+
return result;
108+
}
109+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
110+
}
111+
112+
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
113+
{
114+
if ((endpointConfiguration == EndpointConfiguration.CustomBinding_IService))
115+
{
116+
return new System.ServiceModel.EndpointAddress("net.tcp://localhost:8189/Service");
117+
}
118+
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
119+
}
120+
121+
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
122+
{
123+
return ServiceClient.GetBindingForEndpoint(EndpointConfiguration.CustomBinding_IService);
124+
}
125+
126+
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
127+
{
128+
return ServiceClient.GetEndpointAddress(EndpointConfiguration.CustomBinding_IService);
129+
}
130+
131+
public enum EndpointConfiguration
132+
{
133+
134+
CustomBinding_IService,
135+
}
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
3+
"version": "99.99.99",
4+
"options": {
5+
"inputs": [
6+
"../../../../../src/dotnet-svcutil/lib/tests/TestCases/wsdl/SspiNegoAuthRequireCancelTokenFasle.wsdl"
7+
],
8+
"namespaceMappings": [
9+
"*, SspiNegoAuthRequireCancelTokenFasle_NS"
10+
],
11+
"outputFile": "Reference.cs",
12+
"targetFramework": "N.N",
13+
"typeReuseMode": "None"
14+
}
15+
}

0 commit comments

Comments
 (0)