diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Client.csproj b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Client.csproj index 9aebac1dbcb..8feacdebbe9 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Client.csproj +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Client.csproj @@ -1,99 +1,36 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>8.0.50727</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{97E8A065-31ED-4506-B3A4-6B2E2ED5B124}</ProjectGuid> + <TargetFrameworks>net462;net6.0</TargetFrameworks> <OutputType>Exe</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>Microsoft.Samples.GZipEncoder</RootNamespace> - <AssemblyName>Client</AssemblyName> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> - <FileUpgradeFlags> - </FileUpgradeFlags> - <OldToolsVersion>2.0</OldToolsVersion> - <UpgradeBackupLocation /> - <PublishUrl>publish\</PublishUrl> - <Install>true</Install> - <InstallFrom>Disk</InstallFrom> - <UpdateEnabled>false</UpdateEnabled> - <UpdateMode>Foreground</UpdateMode> - <UpdateInterval>7</UpdateInterval> - <UpdateIntervalUnits>Days</UpdateIntervalUnits> - <UpdatePeriodically>false</UpdatePeriodically> - <UpdateRequired>false</UpdateRequired> - <MapFileExtensions>true</MapFileExtensions> - <ApplicationRevision>0</ApplicationRevision> - <ApplicationVersion>1.0.0.%2a</ApplicationVersion> - <IsWebBootstrapper>false</IsWebBootstrapper> - <UseApplicationTrust>false</UseApplicationTrust> - <BootstrapperEnabled>true</BootstrapperEnabled> - <TargetFrameworkProfile /> + <Title>Client</Title> + <Description>GZipEncoder</Description> + <Company>Microsoft Corporation</Company> + <Product>Windows Communication Foundation and Windows Workflow Foundation SDK</Product> + <Copyright>Copyright (c) Microsoft Corporation</Copyright> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.configuration" /> - <Reference Include="System.Data" /> - <Reference Include="System.Runtime.Serialization" /> - <Reference Include="System.ServiceModel" /> - <Reference Include="System.Xml" /> + + <ItemGroup Condition=" '$(TargetFramework)' == 'net462' "> + <None Remove="Connected Services\Microsoft.Samples.GZipEncoder\ConnectedService.json" /> + <Compile Remove="Connected Services\Microsoft.Samples.GZipEncoder\Reference.cs" /> + <None Include="Connected Services\Microsoft.Samples.GZipEncoder\Reference.cs" /> </ItemGroup> - <ItemGroup> - <Compile Include="generatedClient.cs" /> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> + + <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' "> + <None Remove="App.config" /> + <Compile Remove="generatedClient.cs" /> + <None Include="generatedClient.cs" /> </ItemGroup> - <ItemGroup> - <None Include="app.config" /> + + <ItemGroup Condition=" '$(TargetFramework)' == 'net462' "> + <Reference Include="System.ServiceModel" /> </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\GZipEncoder\GZipEncoder.csproj"> - <Project>{3EB736C4-62EA-4887-B040-948B13EF29B9}</Project> - <Name>GZipEncoder</Name> - </ProjectReference> + + <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' "> + <PackageReference Include="System.ServiceModel.Primitives" Version="6.*" /> + <PackageReference Include="System.ServiceModel.Http" Version="6.*" /> </ItemGroup> + <ItemGroup> - <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> - <Visible>False</Visible> - <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> - <Install>false</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> - <Visible>False</Visible> - <ProductName>.NET Framework 3.5 SP1</ProductName> - <Install>true</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.VisualBasic.PowerPacks.10.0"> - <Visible>False</Visible> - <ProductName>Microsoft Visual Basic PowerPacks 10.0</ProductName> - <Install>true</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> - <Visible>False</Visible> - <ProductName>Windows Installer 3.1</ProductName> - <Install>true</Install> - </BootstrapperPackage> + <ProjectReference Include="..\GZipEncoder\GZipEncoder.csproj" /> </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> -</Project> \ No newline at end of file +</Project> diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Connected Services/Microsoft.Samples.GZipEncoder/ConnectedService.json b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Connected Services/Microsoft.Samples.GZipEncoder/ConnectedService.json new file mode 100644 index 00000000000..34a34d95d1e --- /dev/null +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Connected Services/Microsoft.Samples.GZipEncoder/ConnectedService.json @@ -0,0 +1,17 @@ +{ + "ExtendedData": { + "inputs": [ + "http://localhost:8000/samples/GZipEncoder?wsdl" + ], + "collectionTypes": [ + "System.Array", + "System.Collections.Generic.Dictionary`2" + ], + "namespaceMappings": [ + "*, Microsoft.Samples.GZipEncoder" + ], + "sync": true, + "targetFramework": "net6.0", + "typeReuseMode": "None" + } +} \ No newline at end of file diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Connected Services/Microsoft.Samples.GZipEncoder/Reference.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Connected Services/Microsoft.Samples.GZipEncoder/Reference.cs new file mode 100644 index 00000000000..c93b24094db --- /dev/null +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Connected Services/Microsoft.Samples.GZipEncoder/Reference.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// <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 Microsoft.Samples.GZipEncoder +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] + [System.ServiceModel.ServiceContractAttribute(ConfigurationName="Microsoft.Samples.GZipEncoder.ISampleServer")] + public interface ISampleServer + { + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISampleServer/Echo", ReplyAction="http://tempuri.org/ISampleServer/EchoResponse")] + string Echo(string input); + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISampleServer/Echo", ReplyAction="http://tempuri.org/ISampleServer/EchoResponse")] + System.Threading.Tasks.Task<string> EchoAsync(string input); + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISampleServer/BigEcho", ReplyAction="http://tempuri.org/ISampleServer/BigEchoResponse")] + string[] BigEcho(string[] input); + + [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISampleServer/BigEcho", ReplyAction="http://tempuri.org/ISampleServer/BigEchoResponse")] + System.Threading.Tasks.Task<string[]> BigEchoAsync(string[] input); + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] + public interface ISampleServerChannel : Microsoft.Samples.GZipEncoder.ISampleServer, System.ServiceModel.IClientChannel + { + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")] + public partial class SampleServerClient : System.ServiceModel.ClientBase<Microsoft.Samples.GZipEncoder.ISampleServer>, Microsoft.Samples.GZipEncoder.ISampleServer + { + + public SampleServerClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : + base(binding, remoteAddress) + { + } + + public string Echo(string input) + { + return base.Channel.Echo(input); + } + + public System.Threading.Tasks.Task<string> EchoAsync(string input) + { + return base.Channel.EchoAsync(input); + } + + public string[] BigEcho(string[] input) + { + return base.Channel.BigEcho(input); + } + + public System.Threading.Tasks.Task<string[]> BigEchoAsync(string[] input) + { + return base.Channel.BigEchoAsync(input); + } + + 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)); + } + } +} diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Program.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Program.cs index 08e9c9b1b40..025db314ee5 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Program.cs +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Program.cs @@ -3,6 +3,8 @@ //---------------------------------------------------------------- using System; +using System.ServiceModel; +using System.ServiceModel.Channels; namespace Microsoft.Samples.GZipEncoder { @@ -10,7 +12,14 @@ static class Program { static void Main() { +#if NET6_0_OR_GREATER + Binding binding = new CustomBinding(new GZipMessageEncodingBindingElement(), new HttpTransportBindingElement()); + EndpointAddress endpointAddress = new EndpointAddress(new Uri("http://localhost:8000/samples/GZipEncoder")); + SampleServerClient client = new SampleServerClient(binding, endpointAddress); +#else SampleServerClient client = new SampleServerClient(); +#endif + Console.WriteLine("Calling Echo(string):"); Console.WriteLine("Server responds: {0}", client.Echo("Simple hello")); diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Properties/AssemblyInfo.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Properties/AssemblyInfo.cs deleted file mode 100644 index f1e0dd31444..00000000000 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: ComVisible(false)] -[assembly: CLSCompliant(true)] -[assembly: AssemblyTitle("Client")] -[assembly: AssemblyDescription("GZipEncoder")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft Corporation")] -[assembly: AssemblyProduct("Windows Communication Foundation and Windows Workflow Foundation SDK")] -[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("4.0.0.0")] -[assembly: AssemblyFileVersion("4.0.0.0")] \ No newline at end of file diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/app.config b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/app.config index 6b6fb9dd944..e3afbcc87ce 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/app.config +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Client/app.config @@ -24,4 +24,4 @@ </customBinding> </bindings> </system.serviceModel> -<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> +</configuration> diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipEncoder.csproj b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipEncoder.csproj index e7ca1af23ef..a53e97c32fd 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipEncoder.csproj +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipEncoder.csproj @@ -1,87 +1,22 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>8.0.50727</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{3EB736C4-62EA-4887-B040-948B13EF29B9}</ProjectGuid> + <TargetFrameworks>net462;net6.0</TargetFrameworks> <OutputType>Library</OutputType> - <RootNamespace>Microsoft.Samples.GZipEncoder</RootNamespace> - <AssemblyName>GZipEncoder</AssemblyName> - <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> - <FileUpgradeFlags> - </FileUpgradeFlags> - <OldToolsVersion>2.0</OldToolsVersion> - <UpgradeBackupLocation /> - <PublishUrl>publish\</PublishUrl> - <Install>true</Install> - <InstallFrom>Disk</InstallFrom> - <UpdateEnabled>false</UpdateEnabled> - <UpdateMode>Foreground</UpdateMode> - <UpdateInterval>7</UpdateInterval> - <UpdateIntervalUnits>Days</UpdateIntervalUnits> - <UpdatePeriodically>false</UpdatePeriodically> - <UpdateRequired>false</UpdateRequired> - <MapFileExtensions>true</MapFileExtensions> - <ApplicationRevision>0</ApplicationRevision> - <ApplicationVersion>1.0.0.%2a</ApplicationVersion> - <IsWebBootstrapper>false</IsWebBootstrapper> - <UseApplicationTrust>false</UseApplicationTrust> - <BootstrapperEnabled>true</BootstrapperEnabled> - <TargetFrameworkProfile /> + <Title>GZipEncoder</Title> + <Description>GZipEncoder</Description> + <Company>Microsoft Corporation</Company> + <Product>Windows Communication Foundation and Windows Workflow Foundation SDK</Product> + <Copyright>Copyright (c) Microsoft Corporation</Copyright> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>.\bin\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>.\bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> + + <ItemGroup Condition=" '$(TargetFramework)' == 'net462' "> <Reference Include="System.Configuration" /> - <Reference Include="System.Data" /> - <Reference Include="System.Runtime.Serialization" /> <Reference Include="System.ServiceModel" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="GZipMessageEncoderFactory.cs" /> - <Compile Include="GZipMessageEncodingBindingElement.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="GZipMessageEncodingBindingElementImporter.cs" /> </ItemGroup> - <ItemGroup> - <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> - <Visible>False</Visible> - <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> - <Install>false</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> - <Visible>False</Visible> - <ProductName>.NET Framework 3.5 SP1</ProductName> - <Install>true</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.VisualBasic.PowerPacks.10.0"> - <Visible>False</Visible> - <ProductName>Microsoft Visual Basic PowerPacks 10.0</ProductName> - <Install>true</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> - <Visible>False</Visible> - <ProductName>Windows Installer 3.1</ProductName> - <Install>true</Install> - </BootstrapperPackage> + + <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' "> + <PackageReference Include="System.ServiceModel.Primitives" Version="6.*" /> + <PackageReference Include="System.ServiceModel.Http" Version="6.*" /> </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> -</Project> \ No newline at end of file + +</Project> diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncoderFactory.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncoderFactory.cs index a96cb643784..1e3fb5fb3d4 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncoderFactory.cs +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncoderFactory.cs @@ -12,7 +12,7 @@ namespace Microsoft.Samples.GZipEncoder //This class is used to create the custom encoder (GZipMessageEncoder) internal class GZipMessageEncoderFactory : MessageEncoderFactory { - MessageEncoder encoder; + private readonly MessageEncoder _encoder; //The GZip encoder wraps an inner encoder //We require a factory to be passed in that will create this inner encoder @@ -20,30 +20,24 @@ public GZipMessageEncoderFactory(MessageEncoderFactory messageEncoderFactory) { if (messageEncoderFactory == null) throw new ArgumentNullException("messageEncoderFactory", "A valid message encoder factory must be passed to the GZipEncoder"); - encoder = new GZipMessageEncoder(messageEncoderFactory.Encoder); + _encoder = new GZipMessageEncoder(messageEncoderFactory.Encoder); } //The service framework uses this property to obtain an encoder from this encoder factory - public override MessageEncoder Encoder - { - get { return encoder; } - } + public override MessageEncoder Encoder => _encoder; - public override MessageVersion MessageVersion - { - get { return encoder.MessageVersion; } - } + public override MessageVersion MessageVersion => _encoder.MessageVersion; //This is the actual GZip encoder - class GZipMessageEncoder : MessageEncoder + private class GZipMessageEncoder : MessageEncoder { - static string GZipContentType = "application/x-gzip"; + private const string GZipContentType = "application/x-gzip"; //This implementation wraps an inner encoder that actually converts a WCF Message //into textual XML, binary XML or some other format. This implementation then compresses the results. //The opposite happens when reading messages. //This member stores this inner encoder. - MessageEncoder innerEncoder; + private readonly MessageEncoder _innerEncoder; //We require an inner encoder to be supplied (see comment above) internal GZipMessageEncoder(MessageEncoder messageEncoder) @@ -51,30 +45,21 @@ internal GZipMessageEncoder(MessageEncoder messageEncoder) { if (messageEncoder == null) throw new ArgumentNullException("messageEncoder", "A valid message encoder must be passed to the GZipEncoder"); - innerEncoder = messageEncoder; + _innerEncoder = messageEncoder; } - public override string ContentType - { - get { return GZipContentType; } - } + public override string ContentType => GZipContentType; - public override string MediaType - { - get { return GZipContentType; } - } + public override string MediaType => GZipContentType; //SOAP version to use - we delegate to the inner encoder for this - public override MessageVersion MessageVersion - { - get { return innerEncoder.MessageVersion; } - } + public override MessageVersion MessageVersion => _innerEncoder.MessageVersion; //Helper method to compress an array of bytes - static ArraySegment<byte> CompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager, int messageOffset) + private static ArraySegment<byte> CompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager, int messageOffset) { MemoryStream memoryStream = new MemoryStream(); - + using (GZipStream gzStream = new GZipStream(memoryStream, CompressionMode.Compress, true)) { gzStream.Write(buffer.Array, buffer.Offset, buffer.Count); @@ -93,7 +78,7 @@ static ArraySegment<byte> CompressBuffer(ArraySegment<byte> buffer, BufferManage } //Helper method to decompress an array of bytes - static ArraySegment<byte> DecompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager) + private static ArraySegment<byte> DecompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager) { MemoryStream memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count); MemoryStream decompressedStream = new MemoryStream(); @@ -130,7 +115,7 @@ public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager buf //Decompress the buffer ArraySegment<byte> decompressedBuffer = DecompressBuffer(buffer, bufferManager); //Use the inner encoder to decode the decompressed buffer - Message returnMessage = innerEncoder.ReadMessage(decompressedBuffer, bufferManager); + Message returnMessage = _innerEncoder.ReadMessage(decompressedBuffer, bufferManager); returnMessage.Properties.Encoder = this; return returnMessage; } @@ -139,7 +124,7 @@ public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager buf public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { //Use the inner encoder to encode a Message into a buffered byte array - ArraySegment<byte> buffer = innerEncoder.WriteMessage(message, maxMessageSize, bufferManager, 0); + ArraySegment<byte> buffer = _innerEncoder.WriteMessage(message, maxMessageSize, bufferManager, 0); //Compress the resulting byte array return CompressBuffer(buffer, bufferManager, messageOffset); } @@ -150,14 +135,14 @@ public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeader //This will ensure that the inner stream gets closed when the message gets closed, which //will ensure that resources are available for reuse/release. GZipStream gzStream = new GZipStream(stream, CompressionMode.Decompress, false); - return innerEncoder.ReadMessage(gzStream, maxSizeOfHeaders); + return _innerEncoder.ReadMessage(gzStream, maxSizeOfHeaders); } public override void WriteMessage(Message message, System.IO.Stream stream) { using (GZipStream gzStream = new GZipStream(stream, CompressionMode.Compress, true)) { - innerEncoder.WriteMessage(message, gzStream); + _innerEncoder.WriteMessage(message, gzStream); } // innerEncoder.WriteMessage(message, gzStream) depends on that it can flush data by flushing diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElement.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElement.cs index 15a17dd5a93..f4c244cba81 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElement.cs +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElement.cs @@ -5,14 +5,13 @@ using System; using System.Configuration; using System.ServiceModel.Channels; -using System.ServiceModel.Configuration; using System.ServiceModel.Description; using System.Xml; namespace Microsoft.Samples.GZipEncoder { // This is constants for GZip message encoding policy. - static class GZipMessageEncodingPolicyConstants + internal static class GZipMessageEncodingPolicyConstants { public const string GZipEncodingName = "GZipEncoding"; public const string GZipEncodingNamespace = "http://schemas.microsoft.com/ws/06/2004/mspolicy/netgzip1"; @@ -20,54 +19,41 @@ static class GZipMessageEncodingPolicyConstants } //This is the binding element that, when plugged into a custom binding, will enable the GZip encoder - public sealed class GZipMessageEncodingBindingElement + public sealed class GZipMessageEncodingBindingElement : MessageEncodingBindingElement //BindingElement +#if NET462_OR_GREATER , IPolicyExportExtension +#endif { - //We will use an inner binding element to store information required for the inner encoder - MessageEncodingBindingElement innerBindingElement; - //By default, use the default text encoder as the inner encoder public GZipMessageEncodingBindingElement() : this(new TextMessageEncodingBindingElement()) { } - public GZipMessageEncodingBindingElement(MessageEncodingBindingElement messageEncoderBindingElement) - { - this.innerBindingElement = messageEncoderBindingElement; - } + public GZipMessageEncodingBindingElement(MessageEncodingBindingElement messageEncoderBindingElement) => InnerMessageEncodingBindingElement = messageEncoderBindingElement; - public MessageEncodingBindingElement InnerMessageEncodingBindingElement - { - get { return innerBindingElement; } - set { innerBindingElement = value; } - } + //We will use an inner binding element to store information required for the inner encoder + public MessageEncodingBindingElement InnerMessageEncodingBindingElement { get; set; } //Main entry point into the encoder binding element. Called by WCF to get the factory that will create the //message encoder - public override MessageEncoderFactory CreateMessageEncoderFactory() - { - return new GZipMessageEncoderFactory(innerBindingElement.CreateMessageEncoderFactory()); - } - + public override MessageEncoderFactory CreateMessageEncoderFactory() => new GZipMessageEncoderFactory(InnerMessageEncodingBindingElement.CreateMessageEncoderFactory()); + public override MessageVersion MessageVersion { - get { return innerBindingElement.MessageVersion; } - set { innerBindingElement.MessageVersion = value; } + get => InnerMessageEncodingBindingElement.MessageVersion; + set => InnerMessageEncodingBindingElement.MessageVersion = value; } - public override BindingElement Clone() - { - return new GZipMessageEncodingBindingElement(this.innerBindingElement); - } + public override BindingElement Clone() => new GZipMessageEncodingBindingElement(this.InnerMessageEncodingBindingElement); public override T GetProperty<T>(BindingContext context) { if (typeof(T) == typeof(XmlDictionaryReaderQuotas)) { - return innerBindingElement.GetProperty<T>(context); + return InnerMessageEncodingBindingElement.GetProperty<T>(context); } - else + else { return base.GetProperty<T>(context); } @@ -82,6 +68,7 @@ public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingC return context.BuildInnerChannelFactory<TChannel>(); } +#if NET462_OR_GREATER public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context) { if (context == null) @@ -112,29 +99,28 @@ void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConver GZipMessageEncodingPolicyConstants.GZipEncodingName, GZipMessageEncodingPolicyConstants.GZipEncodingNamespace)); } +#endif } +#if NET462_OR_GREATER //This class is necessary to be able to plug in the GZip encoder binding element through //a configuration file - public class GZipMessageEncodingElement : BindingElementExtensionElement + public class GZipMessageEncodingElement : System.ServiceModel.Configuration.BindingElementExtensionElement { public GZipMessageEncodingElement() { } //Called by the WCF to discover the type of binding element this config section enables - public override Type BindingElementType - { - get { return typeof(GZipMessageEncodingBindingElement); } - } + public override Type BindingElementType => typeof(GZipMessageEncodingBindingElement); //The only property we need to configure for our binding element is the type of //inner encoder to use. Here, we support text and binary. [ConfigurationProperty("innerMessageEncoding", DefaultValue = "textMessageEncoding")] public string InnerMessageEncoding { - get { return (string)base["innerMessageEncoding"]; } - set { base["innerMessageEncoding"] = value; } + get => (string)base["innerMessageEncoding"]; + set => base["innerMessageEncoding"] = value; } //Called by the WCF to apply the configuration settings (the property above) to the binding element @@ -164,4 +150,5 @@ protected override BindingElement CreateBindingElement() return bindingElement; } } +#endif } diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElementImporter.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElementImporter.cs index d85f166eb64..5296186e9fc 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElementImporter.cs +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/GZipMessageEncodingBindingElementImporter.cs @@ -7,6 +7,7 @@ using System.ServiceModel.Description; using System.Xml; +#if NET462_OR_GREATER namespace Microsoft.Samples.GZipEncoder { public class GZipMessageEncodingBindingElementImporter : IPolicyImportExtension @@ -42,4 +43,4 @@ void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConver } } } - +#endif diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/Properties/AssemblyInfo.cs b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/Properties/AssemblyInfo.cs deleted file mode 100644 index 631687d2f82..00000000000 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/GZipEncoder/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,23 +0,0 @@ - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: ComVisible(false)] -[assembly: CLSCompliant(true)] -[assembly: AssemblyTitle("GZipEncoder")] -[assembly: AssemblyDescription("GZipEncoder")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft Corporation")] -[assembly: AssemblyProduct("Windows Communication Foundation and Windows Workflow Foundation SDK")] -[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("4.0.0.0")] -[assembly: AssemblyFileVersion("4.0.0.0")] \ No newline at end of file diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/Server.csproj b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/Server.csproj index 56480530d08..ddff80555b6 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/Server.csproj +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/Server.csproj @@ -1,36 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.50727</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{9746FE53-56C5-4ED5-9214-D93F457A0560}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>Microsoft.Samples.GZipEncoder</RootNamespace> <AssemblyName>Server</AssemblyName> <WarningLevel>4</WarningLevel> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> - <FileUpgradeFlags> - </FileUpgradeFlags> - <OldToolsVersion>2.0</OldToolsVersion> - <UpgradeBackupLocation /> + <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <PublishUrl>publish\</PublishUrl> - <Install>true</Install> - <InstallFrom>Disk</InstallFrom> - <UpdateEnabled>false</UpdateEnabled> - <UpdateMode>Foreground</UpdateMode> - <UpdateInterval>7</UpdateInterval> - <UpdateIntervalUnits>Days</UpdateIntervalUnits> - <UpdatePeriodically>false</UpdatePeriodically> - <UpdateRequired>false</UpdateRequired> - <MapFileExtensions>true</MapFileExtensions> - <ApplicationRevision>0</ApplicationRevision> - <ApplicationVersion>1.0.0.%2a</ApplicationVersion> - <IsWebBootstrapper>false</IsWebBootstrapper> - <UseApplicationTrust>false</UseApplicationTrust> - <BootstrapperEnabled>true</BootstrapperEnabled> - <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -39,6 +20,7 @@ <OutputPath>.\bin\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>false</Prefer32Bit> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -46,6 +28,7 @@ <OutputPath>.\bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <Prefer32Bit>false</Prefer32Bit> </PropertyGroup> <ItemGroup> <Reference Include="System" /> @@ -66,27 +49,5 @@ <Name>GZipEncoder</Name> </ProjectReference> </ItemGroup> - <ItemGroup> - <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> - <Visible>False</Visible> - <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> - <Install>false</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> - <Visible>False</Visible> - <ProductName>.NET Framework 3.5 SP1</ProductName> - <Install>true</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.VisualBasic.PowerPacks.10.0"> - <Visible>False</Visible> - <ProductName>Microsoft Visual Basic PowerPacks 10.0</ProductName> - <Install>true</Install> - </BootstrapperPackage> - <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> - <Visible>False</Visible> - <ProductName>Windows Installer 3.1</ProductName> - <Install>true</Install> - </BootstrapperPackage> - </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> -</Project> \ No newline at end of file + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project> diff --git a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/app.config b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/app.config index 83bfb8215ab..9cefe0ef050 100644 --- a/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/app.config +++ b/framework/wcf/Extensibility/MessageEncoder/Compression/CS/Server/app.config @@ -3,20 +3,27 @@ <system.serviceModel> <extensions> <bindingElementExtensions> - <add name="gzipMessageEncoding" type="Microsoft.Samples.GZipEncoder.GZipMessageEncodingElement, GZipEncoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" /> + <add name="gzipMessageEncoding" type="Microsoft.Samples.GZipEncoder.GZipMessageEncodingElement, GZipEncoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null"/> </bindingElementExtensions> </extensions> <protocolMapping> - <add scheme="http" binding="customBinding" /> + <add scheme="http" binding="customBinding"/> </protocolMapping> <bindings> <customBinding> <binding> <gzipMessageEncoding innerMessageEncoding="textMessageEncoding"/> - <httpTransport hostNameComparisonMode="StrongWildcard" manualAddressing="False" maxReceivedMessageSize="65536" authenticationScheme="Anonymous" bypassProxyOnLocal="False" realm="" useDefaultWebProxy="True"/> + <httpTransport/> </binding> </customBinding> </bindings> + <behaviors> + <serviceBehaviors> + <behavior> + <serviceMetadata httpGetEnabled="True"/> + </behavior> + </serviceBehaviors> + </behaviors> </system.serviceModel> <system.diagnostics> <sources> @@ -28,4 +35,4 @@ </sources> <trace autoflush="true"/> </system.diagnostics> -<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> +</configuration>