Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update WCF sample Instancing/Lifetime to conditionally support .NET framework / Core #6281

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
</bindings>

</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved.

using System;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace Microsoft.ServiceModel.Samples
{
[ServiceContract(SessionMode=SessionMode.Required)]
interface IEchoService
[ServiceContract(SessionMode = SessionMode.Required)]
internal interface IEchoService
{
[OperationContract]
string Echo(string value);
}

public static class CustomHeader
{
public static readonly String HeaderName = "InstanceId";
public static readonly String HeaderNamespace = "http://Microsoft.ServiceModel.Samples/Lifetime";
public const string HeaderName = "InstanceId";
public const string HeaderNamespace = "http://Microsoft.ServiceModel.Samples/Lifetime";
}

class Program
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(
"Press <enter> to open a channel and send a request.");
Console.WriteLine("Press <enter> to open a channel and send a request.");

Console.ReadLine();

MessageHeader shareableInstanceContextHeader = MessageHeader.CreateHeader(
CustomHeader.HeaderName,
CustomHeader.HeaderNamespace,
Guid.NewGuid().ToString());

ChannelFactory<IEchoService> channelFactory =
new ChannelFactory<IEchoService>("echoservice");

#if NET6_0_OR_GREATER
CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement());
EndpointAddress endpointAddress = new EndpointAddress(new Uri("net.tcp://localhost:9000/echoservice"));
ChannelFactory<IEchoService> channelFactory = new ChannelFactory<IEchoService>(binding, endpointAddress);
#else
ChannelFactory<IEchoService> channelFactory = new ChannelFactory<IEchoService>("echoservice");
#endif
IEchoService proxy = channelFactory.CreateChannel();


using (new OperationContextScope((IClientChannel)proxy))
{
OperationContext.Current.OutgoingMessageHeaders.Add(shareableInstanceContextHeader);
Expand All @@ -52,8 +54,8 @@ static void Main(string[] args)
Console.WriteLine("Channel No 1 closed.");

Console.WriteLine(
"Press <ENTER> to send another request from a different channel " +
"to the same instance. ");
"Press <ENTER> to send another request from a different channel " +
"to the same instance. ");

Console.ReadLine();

Expand All @@ -66,11 +68,11 @@ static void Main(string[] args)
Console.WriteLine("Service returned: " + proxy.Echo("Apple"));
Console.ForegroundColor = ConsoleColor.Gray;
}

((IChannel)proxy).Close();

Console.WriteLine("Channel No 2 closed.");

Console.WriteLine("Press <ENTER> to complete test.");
Console.ReadLine();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,100 +1,24 @@
<?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>{141A9C5A-0610-4F1B-BDD5-1EAF8416850E}</ProjectGuid>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.ServiceModel.Samples</RootNamespace>
<AssemblyName>Client</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<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>Lifetime sample</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\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<None Remove="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.ServiceModel" />
</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.NetTcp" Version="6.*" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

This file was deleted.

Loading
Loading