Skip to content

Commit 9a181d8

Browse files
committed
Update WCF sample Instancing/Lifetime to conditionally support .NET framework / Core
1 parent 3499221 commit 9a181d8

File tree

15 files changed

+152
-382
lines changed

15 files changed

+152
-382
lines changed

framework/wcf/Extensibility/Instancing/Lifetime/CS/client/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
</bindings>
1717

1818
</system.serviceModel>
19-
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
19+
</configuration>

framework/wcf/Extensibility/Instancing/Lifetime/CS/client/Client.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
// Copyright (c) Microsoft Corporation. All Rights Reserved.
22

33
using System;
4-
using System.ServiceModel.Channels;
54
using System.ServiceModel;
5+
using System.ServiceModel.Channels;
66

77
namespace Microsoft.ServiceModel.Samples
88
{
9-
[ServiceContract(SessionMode=SessionMode.Required)]
10-
interface IEchoService
9+
[ServiceContract(SessionMode = SessionMode.Required)]
10+
internal interface IEchoService
1111
{
1212
[OperationContract]
1313
string Echo(string value);
1414
}
1515

1616
public static class CustomHeader
1717
{
18-
public static readonly String HeaderName = "InstanceId";
19-
public static readonly String HeaderNamespace = "http://Microsoft.ServiceModel.Samples/Lifetime";
18+
public const string HeaderName = "InstanceId";
19+
public const string HeaderNamespace = "http://Microsoft.ServiceModel.Samples/Lifetime";
2020
}
2121

22-
class Program
22+
internal class Program
2323
{
2424
static void Main(string[] args)
2525
{
26-
Console.WriteLine(
27-
"Press <enter> to open a channel and send a request.");
26+
Console.WriteLine("Press <enter> to open a channel and send a request.");
2827

2928
Console.ReadLine();
30-
29+
3130
MessageHeader shareableInstanceContextHeader = MessageHeader.CreateHeader(
3231
CustomHeader.HeaderName,
3332
CustomHeader.HeaderNamespace,
3433
Guid.NewGuid().ToString());
3534

36-
ChannelFactory<IEchoService> channelFactory =
37-
new ChannelFactory<IEchoService>("echoservice");
38-
35+
#if NET6_0_OR_GREATER
36+
CustomBinding binding = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement());
37+
EndpointAddress endpointAddress = new EndpointAddress(new Uri("net.tcp://localhost:9000/echoservice"));
38+
ChannelFactory<IEchoService> channelFactory = new ChannelFactory<IEchoService>(binding, endpointAddress);
39+
#else
40+
ChannelFactory<IEchoService> channelFactory = new ChannelFactory<IEchoService>("echoservice");
41+
#endif
3942
IEchoService proxy = channelFactory.CreateChannel();
4043

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

5456
Console.WriteLine(
55-
"Press <ENTER> to send another request from a different channel " +
56-
"to the same instance. ");
57+
"Press <ENTER> to send another request from a different channel " +
58+
"to the same instance. ");
5759

5860
Console.ReadLine();
5961

@@ -66,11 +68,11 @@ static void Main(string[] args)
6668
Console.WriteLine("Service returned: " + proxy.Echo("Apple"));
6769
Console.ForegroundColor = ConsoleColor.Gray;
6870
}
69-
71+
7072
((IChannel)proxy).Close();
7173

7274
Console.WriteLine("Channel No 2 closed.");
73-
75+
7476
Console.WriteLine("Press <ENTER> to complete test.");
7577
Console.ReadLine();
7678
}
Lines changed: 18 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,24 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.50727</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>{141A9C5A-0610-4F1B-BDD5-1EAF8416850E}</ProjectGuid>
3+
<TargetFrameworks>net462;net6.0</TargetFrameworks>
94
<OutputType>Exe</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>Microsoft.ServiceModel.Samples</RootNamespace>
12-
<AssemblyName>Client</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14-
<FileUpgradeFlags>
15-
</FileUpgradeFlags>
16-
<UpgradeBackupLocation>
17-
</UpgradeBackupLocation>
18-
<OldToolsVersion>2.0</OldToolsVersion>
19-
<PublishUrl>publish\</PublishUrl>
20-
<Install>true</Install>
21-
<InstallFrom>Disk</InstallFrom>
22-
<UpdateEnabled>false</UpdateEnabled>
23-
<UpdateMode>Foreground</UpdateMode>
24-
<UpdateInterval>7</UpdateInterval>
25-
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
26-
<UpdatePeriodically>false</UpdatePeriodically>
27-
<UpdateRequired>false</UpdateRequired>
28-
<MapFileExtensions>true</MapFileExtensions>
29-
<ApplicationRevision>0</ApplicationRevision>
30-
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31-
<IsWebBootstrapper>false</IsWebBootstrapper>
32-
<UseApplicationTrust>false</UseApplicationTrust>
33-
<BootstrapperEnabled>true</BootstrapperEnabled>
34-
<TargetFrameworkProfile />
5+
<Title>Client</Title>
6+
<Description>Lifetime sample</Description>
7+
<Company>Microsoft Corporation</Company>
8+
<Product>Windows Communication Foundation and Windows Workflow Foundation SDK</Product>
9+
<Copyright>Copyright (c) Microsoft Corporation</Copyright>
3510
</PropertyGroup>
36-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
37-
<DebugSymbols>true</DebugSymbols>
38-
<DebugType>full</DebugType>
39-
<Optimize>false</Optimize>
40-
<OutputPath>bin\</OutputPath>
41-
<DefineConstants>DEBUG;TRACE</DefineConstants>
42-
<ErrorReport>prompt</ErrorReport>
43-
<WarningLevel>4</WarningLevel>
44-
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
45-
</PropertyGroup>
46-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
47-
<DebugType>pdbonly</DebugType>
48-
<Optimize>true</Optimize>
49-
<OutputPath>bin\</OutputPath>
50-
<DefineConstants>TRACE</DefineConstants>
51-
<ErrorReport>prompt</ErrorReport>
52-
<WarningLevel>4</WarningLevel>
53-
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
54-
</PropertyGroup>
55-
<ItemGroup>
56-
<Reference Include="System" />
57-
<Reference Include="System.Data" />
58-
<Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
59-
<SpecificVersion>False</SpecificVersion>
60-
</Reference>
61-
<Reference Include="System.Xml" />
62-
</ItemGroup>
63-
<ItemGroup>
64-
<Compile Include="Client.cs" />
65-
<Compile Include="Properties\AssemblyInfo.cs" />
11+
12+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
13+
<None Remove="App.config" />
6614
</ItemGroup>
67-
<ItemGroup>
68-
<None Include="App.config" />
15+
16+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
17+
<Reference Include="System.ServiceModel" />
6918
</ItemGroup>
70-
<ItemGroup>
71-
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
72-
<Visible>False</Visible>
73-
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
74-
<Install>false</Install>
75-
</BootstrapperPackage>
76-
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
77-
<Visible>False</Visible>
78-
<ProductName>.NET Framework 3.5 SP1</ProductName>
79-
<Install>true</Install>
80-
</BootstrapperPackage>
81-
<BootstrapperPackage Include="Microsoft.VisualBasic.PowerPacks.10.0">
82-
<Visible>False</Visible>
83-
<ProductName>Microsoft Visual Basic PowerPacks 10.0</ProductName>
84-
<Install>true</Install>
85-
</BootstrapperPackage>
86-
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
87-
<Visible>False</Visible>
88-
<ProductName>Windows Installer 3.1</ProductName>
89-
<Install>true</Install>
90-
</BootstrapperPackage>
19+
20+
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
21+
<PackageReference Include="System.ServiceModel.Primitives" Version="6.*" />
22+
<PackageReference Include="System.ServiceModel.NetTcp" Version="6.*" />
9123
</ItemGroup>
92-
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
93-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
94-
Other similar extension points exist, see Microsoft.Common.targets.
95-
<Target Name="BeforeBuild">
96-
</Target>
97-
<Target Name="AfterBuild">
98-
</Target>
99-
-->
100-
</Project>
24+
</Project>

framework/wcf/Extensibility/Instancing/Lifetime/CS/client/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)