Skip to content

Commit

Permalink
Optimize the referenced wcf package version and add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
imcarolwang committed Apr 30, 2024
1 parent a653daa commit acff7a7
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.ServiceModel;
using System.Threading.Tasks;
using System.Linq;
using System.Xml.Linq;
using static Microsoft.Tools.ServiceModel.Svcutil.TargetFrameworkHelper;

namespace Microsoft.Tools.ServiceModel.Svcutil
{
Expand All @@ -32,7 +32,18 @@ public AddAsyncOpenClose(CommandProcessorOptions options)
{
if (options.TargetFramework.IsDnx)
{
if (TargetFrameworkHelper.NetCoreVersionReferenceTable.TryGetValue(options.TargetFramework.Version, out var referenceTable))
bool findVersion = false;
System.Collections.Generic.List<ProjectDependency> referenceTable = null;
if(options.TargetFramework.Name != FrameworkInfo.Netstandard)
{
findVersion = NetCoreVersionReferenceTable.TryGetValue(options.TargetFramework.Version, out referenceTable);
}
else if (NetStandardToNetCoreVersionMap.Keys.Contains(options.TargetFramework.Version))
{
findVersion = NetCoreVersionReferenceTable.TryGetValue(NetCoreToWCFPackageReferenceVersionMap[NetStandardToNetCoreVersionMap[options.TargetFramework.Version]], out referenceTable);
}

if (findVersion)
{
string version = referenceTable.FirstOrDefault().Version;
string[] vers = version.Split('.');
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-svcutil/lib/src/Shared/FrameworkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public static FrameworkInfo Parse(string fullFrameworkName)
fxInfo.Version = version;
fxInfo.IsDnx = name == Netstandard || name == Netcoreapp || version.Major >= 5;
fxInfo.IsKnownDnx = fxInfo.IsDnx &&
(TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Keys.Any((netstdVersion) => netstdVersion == version) ||
TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Values.Any((netcoreVersion) => netcoreVersion == version));
((name == Netstandard && TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Keys.Any((netstdVersion) => netstdVersion == version)) ||
(name != Netstandard && TargetFrameworkHelper.NetCoreToWCFPackageReferenceVersionMap.Keys.Any((netcoreVersion) => netcoreVersion == version)));

return fxInfo;
}
Expand Down
57 changes: 34 additions & 23 deletions src/dotnet-svcutil/lib/src/Shared/TargetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ internal class TargetFrameworkHelper
{new Version("1.5"), new Version("1.0") },
{new Version("1.6"), new Version("1.0") },
{new Version("1.6.1"), new Version("1.1") },
{new Version("2.0"), new Version("2.0") }
{new Version("2.0"), new Version("5.1") },
{new Version("2.1"), new Version("5.1") }
});

public static ReadOnlyDictionary<Version, Version> NetCoreToWCFPackageReferenceVersionMap { get; } = new ReadOnlyDictionary<Version, Version>(new SortedDictionary<Version, Version>
{
{new Version("1.0"), new Version("1.0") },
{new Version("1.1"), new Version("1.1") },
{new Version("2.0"), new Version("2.0") },
{new Version("2.1"), new Version("2.1") },
{new Version("2.2"), new Version("2.1") },
{new Version("3.0"), new Version("2.1") },
{new Version("3.1"), new Version("3.1") },
{new Version("5.0"), new Version("5.0") },
{new Version("5.1"), new Version("5.1") },
{new Version("6.0"), new Version("6.0") },
{new Version("7.0"), new Version("6.0") },
{new Version("8.0"), new Version("8.0") }
});

internal static SortedDictionary<Version, List<ProjectDependency>> NetCoreVersionReferenceTable = new SortedDictionary<Version, List<ProjectDependency>>
Expand Down Expand Up @@ -65,16 +82,14 @@ internal class TargetFrameworkHelper
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.8.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "4.8.*")
} },
{new Version("6.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Http", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetNamedPipe", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.Primitives", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.UnixDomainSocket", "6.2.*"),
ProjectDependency.FromPackage("System.Web.Services.Description", "6.2.*")
{new Version("5.1"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Duplex", "4.10.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Http", "4.10.*" ),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "4.10.*" ),
ProjectDependency.FromPackage("System.ServiceModel.Security", "4.10.*"),
ProjectDependency.FromPackage("System.ServiceModel.Federation", "4.10.*")
} },
{new Version("7.0"), new List<ProjectDependency> {
{new Version("6.0"), new List<ProjectDependency> {
ProjectDependency.FromPackage("System.ServiceModel.Http", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetTcp", "6.2.*"),
ProjectDependency.FromPackage("System.ServiceModel.NetNamedPipe", "6.2.*"),
Expand Down Expand Up @@ -116,7 +131,7 @@ internal class TargetFrameworkHelper

public static Version MinSupportedNetFxVersion { get; } = new Version("4.5");
public static Version MinSupportedNetStandardVersion { get; } = NetStandardToNetCoreVersionMap.Keys.First();
public static Version MinSupportedNetCoreAppVersion { get; } = NetStandardToNetCoreVersionMap.Values.First();
public static Version MinSupportedNetCoreAppVersion { get; } = NetCoreToWCFPackageReferenceVersionMap.Keys.First();

public static IEnumerable<ProjectDependency> GetWcfProjectReferences(string targetFramework)
{
Expand All @@ -126,9 +141,13 @@ public static IEnumerable<ProjectDependency> GetWcfProjectReferences(string targ
{
if (frameworkInfo.IsDnx)
{
if (NetCoreVersionReferenceTable.ContainsKey(frameworkInfo.Version))
if(frameworkInfo.Name == FrameworkInfo.Netstandard && TargetFrameworkHelper.NetStandardToNetCoreVersionMap.Keys.Contains(frameworkInfo.Version))
{
dependencies = NetCoreVersionReferenceTable[NetCoreToWCFPackageReferenceVersionMap[NetStandardToNetCoreVersionMap[frameworkInfo.Version]]];
}
else if(frameworkInfo.Name != FrameworkInfo.Netstandard && NetCoreToWCFPackageReferenceVersionMap.ContainsKey(frameworkInfo.Version))
{
dependencies = NetCoreVersionReferenceTable[frameworkInfo.Version];
dependencies = NetCoreVersionReferenceTable[NetCoreToWCFPackageReferenceVersionMap[frameworkInfo.Version]];
}
else
{
Expand Down Expand Up @@ -190,16 +209,8 @@ public static Version GetLowestNetCoreVersion(IEnumerable<string> targetFramewor
}
else
{
// target framework is not the minumum standard supported netcore version but it is a known shipped netcore version.
if (TargetFrameworkHelper.NetCoreVersionReferenceTable.ContainsKey(frameworkInfo.Version))
{
netCoreVersion = frameworkInfo.Version;
}
else
{
// target framework is not known to the tool, use the latest known netcore version.
netCoreVersion = TargetFrameworkHelper.NetCoreVersionReferenceTable.Keys.LastOrDefault();
}
// target framework is not known to the tool, use the latest known netcore version.
netCoreVersion = TargetFrameworkHelper.NetCoreVersionReferenceTable.Keys.LastOrDefault();
}

if (targetVersion == null || targetVersion > netCoreVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ServiceReference
{
using System.Runtime.Serialization;


[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.Runtime.Serialization.DataContractAttribute(Name="BinLibrary", Namespace="http://schemas.datacontract.org/2004/07/BinLib")]
public partial class BinLibrary : object
{

private string ValueField;

[System.Runtime.Serialization.DataMemberAttribute()]
public string Value
{
get
{
return this.ValueField;
}
set
{
this.ValueField = value;
}
}
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.Runtime.Serialization.DataContractAttribute(Name="TypeReuseCompositeType", Namespace="http://schemas.datacontract.org/2004/07/TypesLib")]
public partial class TypeReuseCompositeType : object
{

private bool BoolValueField;

private string StringValueField;

[System.Runtime.Serialization.DataMemberAttribute()]
public bool BoolValue
{
get
{
return this.BoolValueField;
}
set
{
this.BoolValueField = value;
}
}

[System.Runtime.Serialization.DataMemberAttribute()]
public string StringValue
{
get
{
return this.StringValueField;
}
set
{
this.StringValueField = value;
}
}
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference.ITypeReuseSvc")]
public interface ITypeReuseSvc
{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ITypeReuseSvc/GetData", ReplyAction="http://tempuri.org/ITypeReuseSvc/GetDataResponse")]
System.Threading.Tasks.Task<ServiceReference.BinLibrary> GetDataAsync(int value);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ITypeReuseSvc/GetDataUsingDataContract", ReplyAction="http://tempuri.org/ITypeReuseSvc/GetDataUsingDataContractResponse")]
System.Threading.Tasks.Task<ServiceReference.TypeReuseCompositeType> GetDataUsingDataContractAsync(ServiceReference.TypeReuseCompositeType composite);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public interface ITypeReuseSvcChannel : ServiceReference.ITypeReuseSvc, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "99.99.99")]
public partial class TypeReuseSvcClient : System.ServiceModel.ClientBase<ServiceReference.ITypeReuseSvc>, ServiceReference.ITypeReuseSvc
{

/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);

public TypeReuseSvcClient() :
base(TypeReuseSvcClient.GetDefaultBinding(), TypeReuseSvcClient.GetDefaultEndpointAddress())
{
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(EndpointConfiguration endpointConfiguration) :
base(TypeReuseSvcClient.GetBindingForEndpoint(endpointConfiguration), TypeReuseSvcClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(TypeReuseSvcClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
base(TypeReuseSvcClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public TypeReuseSvcClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}

public System.Threading.Tasks.Task<ServiceReference.BinLibrary> GetDataAsync(int value)
{
return base.Channel.GetDataAsync(value);
}

public System.Threading.Tasks.Task<ServiceReference.TypeReuseCompositeType> GetDataUsingDataContractAsync(ServiceReference.TypeReuseCompositeType composite)
{
return base.Channel.GetDataUsingDataContractAsync(composite);
}

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.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}

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.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}

private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
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.BasicHttpBinding_ITypeReuseSvc))
{
return new System.ServiceModel.EndpointAddress("http://localhost:51074/TypeReuseSvc.svc");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return TypeReuseSvcClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc);
}

private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return TypeReuseSvcClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc);
}

public enum EndpointConfiguration
{

BasicHttpBinding_ITypeReuseSvc,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
"version": "99.99.99",
"options": {
"inputs": [
"$testCasesPath$/wsdl/Simple.wsdl"
],
"namespaceMappings": [
"*, ServiceReference"
],
"outputFile": "Reference.cs",
"targetFramework": "N.N",
"typeReuseMode": "All"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>N.N</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ 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.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}

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.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}

private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_ITypeReuseSvc))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
<PackageReference Include="System.ServiceModel.*", Version="N.N.N">
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace net50
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Loading

0 comments on commit acff7a7

Please sign in to comment.