From d59f8f371e4038ac4b52044535b976a930db1e52 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 31 Jul 2026 10:53:07 -0700 Subject: [PATCH 1/6] upgrade C# projects to .net 10 --- .../AndCondition/.ctor/ClientForm.cs | 3 +- .../.ctor/CustomElementClient.csproj | 94 +-------------- .../.ctor/ElementProvider.csproj | 96 +-------------- .../Hyperlink/NavigateUri/Readme.txt | 17 --- .../Overview/FlowDocumentSnippets.csproj | 109 +----------------- .../callbackbehaviorattribute/cs/client.cs | 9 +- .../cs/client.csproj | 48 +++----- .../channelfactorybehaviors/cs/client.cs | 7 +- .../channelfactorybehaviors/cs/client.csproj | 80 ++----------- .../cs/iendpointbehaviormessageinspector.cs | 29 +---- .../channelfactorybehaviors/cs/proxycode.cs | 14 --- .../cs/Client/client.csproj | 87 ++------------ .../cs/Host/host.csproj | 86 ++------------ .../cs/Host/hostapplication.cs | 61 +++++----- .../cs/Host/services.cs | 8 +- 15 files changed, 105 insertions(+), 643 deletions(-) delete mode 100644 snippets/csharp/System.Windows.Documents/Hyperlink/NavigateUri/Readme.txt diff --git a/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/ClientForm.cs b/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/ClientForm.cs index 80605dd6024..7eb5b831726 100644 --- a/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/ClientForm.cs +++ b/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/ClientForm.cs @@ -15,7 +15,6 @@ using System.Text; using System.Windows.Forms; using System.Windows.Automation; -using System.Windows; using System.Diagnostics; namespace CustomElementClient @@ -990,4 +989,4 @@ private void btnMisc_Click(object sender, EventArgs e) // ps.SubscribePropertyChange(elementButton); } } // end class -} // end namespace \ No newline at end of file +} // end namespace diff --git a/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/CustomElementClient.csproj b/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/CustomElementClient.csproj index 82909458be6..2ed457e6392 100644 --- a/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/CustomElementClient.csproj +++ b/snippets/csharp/System.Windows.Automation/AndCondition/.ctor/CustomElementClient.csproj @@ -1,96 +1,10 @@ - + - Debug - AnyCPU - 10.0.20821 - 2.0 - {1A1AA924-1E92-4BFF-8D76-E71CF639E3B4} WinExe - Properties + net10.0-windows + true + true CustomElementClient CustomElementClient - true - http://localhost/CustomElementClient/ - true - Web - true - Foreground - 7 - Days - false - false - true - 1.0.0.* - true - v4.8 - - - true - full - false - c:\sd_avalon.binaries.x86chk\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\..\..\..\..\sd_avalon.binaries.x86chk\ - TRACE - prompt - 4 - - - - False - ..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.dll - - - - - - - - False - False - - - False - ..\..\..\..\..\sd_avalon.binaries.x86chk\UIAutomationTypes.dll - False - - - False - ..\..\..\..\..\sd_avalon.binaries.x86chk\WindowsBase.dll - False - - - - - Form - - - ClientForm.cs - - - - - ClientForm.cs - Designer - - - - - - False - .NET Framework 2.0 Beta - true - - - - - - \ No newline at end of file diff --git a/snippets/csharp/System.Windows.Automation/AutomationEventArgs/.ctor/ElementProvider.csproj b/snippets/csharp/System.Windows.Automation/AutomationEventArgs/.ctor/ElementProvider.csproj index c7c27994610..636f8aa0692 100644 --- a/snippets/csharp/System.Windows.Automation/AutomationEventArgs/.ctor/ElementProvider.csproj +++ b/snippets/csharp/System.Windows.Automation/AutomationEventArgs/.ctor/ElementProvider.csproj @@ -1,98 +1,14 @@ - + - Debug - AnyCPU - 10.0.20821 - 2.0 - {60A534E9-F891-4B01-9AD4-5EFDFE6B0B42} WinExe - Properties + net10.0-windows ElementProvider ElementProvider - true - http://localhost/ElementProvider/ - true - Web - true - Foreground - 7 - Days - false - false - true - 1.0.0.* - true - LocalIntranet - false - v4.8 - + true + latest - - true - full - false - C:\sd_avalon.binaries.x86chk\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - False - D:\avalon.binaries.x86chk\UIAutomationClient.dll - - - False - - - False - D:\avalon.binaries.x86chk\UIAutomationTypes.dll - - - False - - - - - Component - - - - - - - ProviderForm.cs - - - Form - - - ProviderForm.cs - - - - - False - .NET Framework 2.0 Beta - true - - + - + - \ No newline at end of file diff --git a/snippets/csharp/System.Windows.Documents/Hyperlink/NavigateUri/Readme.txt b/snippets/csharp/System.Windows.Documents/Hyperlink/NavigateUri/Readme.txt deleted file mode 100644 index 7652ec8fb24..00000000000 --- a/snippets/csharp/System.Windows.Documents/Hyperlink/NavigateUri/Readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -.NET Framework 3.0 XAML Browser Application Readme ----------------------------------- -XAML Browser Applications run in a sandbox with "Internet Permissions". -Only those .NET Framework 3.0 features that have been successfully security reviewed and validated as safe by the .NET Framework 3.0 team will run inside the sandbox. - -.NET Framework 3.0 Item Templates - which work in the sandbox? --------------------------------------------------------- -Won't work by design - .NET Framework 3.0 Window - In the internet zone, you don't have the permission to "popup" new windows. - -Debugging XAML Browser Applications - (F5) --------------------------------------------------------- -In order to successfully debug an XAML Browser Application in Visual Studio, you must enable unmanaged code debugging -via the Debug page in the Properties view. Developers using Visual C# and Visual Basic Express do not need to do this. - -The first time that this project is debugged, a dialog may appear stating that there -is no debug information available for PresentationHost.exe. This dialog can be -safely dismissed. diff --git a/snippets/csharp/System.Windows/TextAlignment/Overview/FlowDocumentSnippets.csproj b/snippets/csharp/System.Windows/TextAlignment/Overview/FlowDocumentSnippets.csproj index 5ca64d959b2..78e143feadc 100644 --- a/snippets/csharp/System.Windows/TextAlignment/Overview/FlowDocumentSnippets.csproj +++ b/snippets/csharp/System.Windows/TextAlignment/Overview/FlowDocumentSnippets.csproj @@ -1,109 +1,12 @@ - - + - Debug - AnyCPU + WinExe + net10.0-windows + true FlowDocumentSnippets FlowDocumentSnippets - winexe - - v4.8 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - 10.0.20821 - {CE41D70B-777B-42E0-BEE4-15853D754276} - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - AllRules.ruleset - - - false - true - .\bin\Release\ - TRACE - AllRules.ruleset - - - - - - - - - - 4.0 - - - - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MyApp.xaml - Code - - - Window1.xaml - Code - - - - False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - False - Microsoft Visual Basic PowerPacks 10.0 - true - - - False - Windows Installer 3.1 - true - + - - \ No newline at end of file + diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs index fbcf80734f5..4163a9a8b41 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs @@ -7,9 +7,7 @@ namespace Microsoft.WCF.Documentation { [CallbackBehaviorAttribute( - IncludeExceptionDetailInFaults= true, - UseSynchronizationContext=true, - ValidateMustUnderstand=true + UseSynchronizationContext=true )] public class Client : SampleDuplexHelloCallback { @@ -22,9 +20,10 @@ public Client() public void Run() { - // Picks up configuration from the configuration file. + System.ServiceModel.Channels.Binding binding = new CustomBinding(); + EndpointAddress address = new EndpointAddress("http://localhost:8080/DuplexHello"); SampleDuplexHelloClient wcfClient - = new SampleDuplexHelloClient(new InstanceContext(this), "WSDualHttpBinding_SampleDuplexHello"); + = new SampleDuplexHelloClient(new InstanceContext(this), binding, address); try { Console.ForegroundColor = ConsoleColor.White; diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj index e17be2cd354..08a5e8332c2 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj @@ -1,48 +1,28 @@ - + - Debug - AnyCPU - {66190530-B4E3-4BF0-94B4-DFE52D15E50F} Exe - false + net10.0 Client Microsoft.WCF.Documentation + disable + disable + false - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - - - pdbonly - true - .\bin\Release\ - TRACE - - - - - - - - + + Always - - - - - - - - - \ No newline at end of file + + + + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs index fc894355651..11a035f29a2 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs @@ -13,12 +13,13 @@ public static void Main() { try { - // Picks up configuration from the config file. + WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message); + EndpointAddress address = new EndpointAddress("http://localhost:8080/ServiceMetadata/SampleService"); ChannelFactory factory - = new ChannelFactory("WSHttpBinding_ISampleService"); + = new ChannelFactory(binding, address); // Add the client side behavior programmatically to all created channels. - factory.Endpoint.Behaviors.Add(new EndpointBehaviorMessageInspector()); + factory.Endpoint.EndpointBehaviors.Add(new EndpointBehaviorMessageInspector()); ISampleServiceChannel wcfClientChannel = factory.CreateChannel(); diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj index 8357f3af5f2..17406f9fb48 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj @@ -1,55 +1,15 @@ - + - Debug - AnyCPU - {66190530-B4E3-4BF0-94B4-DFE52D15E50F} Exe - false + net10.0 Client Microsoft.WCF.Documentation - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - - - pdbonly - true - .\bin\Release\ - TRACE + disable + disable + false + {66190530-B4E3-4BF0-94B4-DFE52D15E50F} - - - - - - - - - + @@ -60,28 +20,8 @@ - - False - .NET Framework 2.0 %28x86%29 - true - - - False - .NET Framework 3.0 %28x86%29 - false - - - False - .NET Framework 3.5 - false - + + + - - - - - - - - \ No newline at end of file diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs index c368d4420f5..9e79164560d 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs @@ -3,14 +3,13 @@ using System; using System.Collections.Generic; using System.ServiceModel; -using System.ServiceModel.Configuration; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; using System.Text; namespace Microsoft.WCF.Documentation { - class EndpointBehaviorMessageInspector : BehaviorExtensionElement, IEndpointBehavior, IDispatchMessageInspector, IClientMessageInspector + class EndpointBehaviorMessageInspector : IEndpointBehavior, IClientMessageInspector { // // IEndpointBehavior Members @@ -21,12 +20,12 @@ public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.Service public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior) { - behavior.MessageInspectors.Add(new EndpointBehaviorMessageInspector()); + behavior.ClientMessageInspectors.Add(new EndpointBehaviorMessageInspector()); } public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher) { - endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new EndpointBehaviorMessageInspector()); + return; } public void Validate(ServiceEndpoint serviceEndpoint) @@ -36,31 +35,15 @@ public void Validate(ServiceEndpoint serviceEndpoint) // // - // BehaviorExtensionElement members - public override Type BehaviorType - { - get { return typeof(EndpointBehaviorMessageInspector); } - } - - protected override object CreateBehavior() + // Sample helper for creating the behavior instance in modern .NET builds. + public static EndpointBehaviorMessageInspector CreateBehavior() { return new EndpointBehaviorMessageInspector(); } // // - // IDispatchMessageInspector Members - - public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext) - { - Console.WriteLine("AfterReceiveRequest called."); - return null; - } - - public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) - { - Console.WriteLine("BeforeSendReply called."); - } + // IClientMessageInspector members // #region IClientMessageInspector Members diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs index 5cdae074f6d..94445685d51 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs @@ -75,20 +75,6 @@ public SampleServiceClient() { } - public SampleServiceClient(string endpointConfigurationName) : - base(endpointConfigurationName) - { - } - - public SampleServiceClient(string endpointConfigurationName, string remoteAddress) : - base(endpointConfigurationName, remoteAddress) - { - } - - public SampleServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : - base(endpointConfigurationName, remoteAddress) - { - } public SampleServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) diff --git a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Client/client.csproj b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Client/client.csproj index fa06ed73113..e8b3b46ba37 100644 --- a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Client/client.csproj +++ b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Client/client.csproj @@ -1,91 +1,28 @@ - - + - Debug - AnyCPU - {66190530-B4E3-4BF0-94B4-DFE52D15E50F} Exe - false + net10.0 Client Microsoft.WCF.Documentation - v4.8 - - - - - 2.0 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - + disable + disable + false - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - AllRules.ruleset - - - pdbonly - true - .\bin\Release\ - TRACE - AllRules.ruleset - - - - - - - - - + + Always + - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - + + + - - - - - - - - - \ No newline at end of file + diff --git a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/host.csproj b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/host.csproj index 5cd2935bb28..9be0cdb7e21 100644 --- a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/host.csproj +++ b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/host.csproj @@ -1,85 +1,13 @@ - - + - Debug - AnyCPU - {907F0C93-0FC2-4419-B0CE-2B775830A3C2} - Exe - false + net10.0 HostApplication Microsoft.WCF.Documentation - v4.8 - - - - - 2.0 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - + disable + disable - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - AllRules.ruleset - - - pdbonly - true - .\bin\Release\ - TRACE - AllRules.ruleset - - - - - - - False - ..\..\..\..\..\Program Files\Reference Assemblies\Microsoft\WinFX\v3.0\System.Runtime.Serialization.dll - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - + + - - - - - \ No newline at end of file + diff --git a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs index d99c1efd630..bd8eeacdac5 100644 --- a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs +++ b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs @@ -1,51 +1,46 @@ using System; -using System.Configuration; -using System.Collections.Generic; -using System.ServiceModel; -using System.Text; +using CoreWCF; +using CoreWCF.Configuration; +using CoreWCF.Description; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.WCF.Documentation { class HostApplication { - static void Main() + static void Main(string[] args) { HostApplication app = new HostApplication(); - app.Run(); + app.Run(args); } - private void Run() + private void Run(string[] args) { - // Create a ServiceHost for the service type and use the base address from configuration. - using (ServiceHost serviceHost = new ServiceHost(typeof(SampleService))) + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + builder.WebHost.UseUrls("http://localhost:8080"); + builder.Services.AddServiceModelServices(); + builder.Services.AddServiceModelMetadata(); + + WebApplication app = builder.Build(); + + app.UseServiceModel(serviceBuilder => { - try - { - // Open the ServiceHostBase to create listeners and start listening for messages. - serviceHost.Open(); + serviceBuilder.AddService(); + serviceBuilder.AddServiceEndpoint( + new WSHttpBinding(SecurityMode.None), + "/SampleService"); - // The service can now be accessed. - Console.WriteLine("The service is ready."); - Console.WriteLine("Press to terminate service."); - Console.ReadLine(); + ServiceMetadataBehavior serviceMetadataBehavior = + app.Services.GetRequiredService(); + serviceMetadataBehavior.HttpGetEnabled = true; + }); - // Close the ServiceHostBase to shutdown the service. - serviceHost.Close(); - } - catch (TimeoutException timeProblem) - { - Console.WriteLine("The service operation timed out. " + timeProblem.Message); - Console.ReadLine(); - serviceHost.Abort(); - } - catch (CommunicationException commProblem) - { - Console.WriteLine("There was a communication problem. " + commProblem.Message); - Console.ReadLine(); - serviceHost.Abort(); - } - } + Console.WriteLine("The service is ready."); + Console.WriteLine("Press Ctrl+C to terminate service."); + app.Run(); } } } diff --git a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/services.cs b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/services.cs index 65cc0322112..6ce5f93c359 100644 --- a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/services.cs +++ b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/services.cs @@ -1,9 +1,8 @@ // using System; using System.Collections.Generic; -using System.Net.Security; using System.Runtime.Serialization; -using System.ServiceModel; +using CoreWCF; using System.Text; namespace Microsoft.WCF.Documentation @@ -14,8 +13,7 @@ public interface ISampleService{ [OperationContract] [FaultContractAttribute( typeof(GreetingFault), - Action="http://www.contoso.com/GreetingFault", - ProtectionLevel=ProtectionLevel.EncryptAndSign + Action="http://www.contoso.com/GreetingFault" )] string SampleMethod(string msg); // @@ -39,7 +37,7 @@ public string Message } } - class SampleService : ISampleService + public class SampleService : ISampleService { #region ISampleService Members From b8298353d94693353cb28d2b30391ef5997a627e Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 31 Jul 2026 16:05:37 -0700 Subject: [PATCH 2/6] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../faultcontractattribute/cs/Host/hostapplication.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs index bd8eeacdac5..506d5a26fab 100644 --- a/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs +++ b/snippets/csharp/VS_Snippets_CFX/faultcontractattribute/cs/Host/hostapplication.cs @@ -28,9 +28,8 @@ private void Run(string[] args) app.UseServiceModel(serviceBuilder => { - serviceBuilder.AddService(); serviceBuilder.AddServiceEndpoint( - new WSHttpBinding(SecurityMode.None), + new WSHttpBinding(SecurityMode.Message), "/SampleService"); ServiceMetadataBehavior serviceMetadataBehavior = From 2eac8461c47e3e4f7490d89a5800aa57d826f2dd Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 31 Jul 2026 16:17:44 -0700 Subject: [PATCH 3/6] small nits --- .../VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs | 2 +- .../csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs index 4163a9a8b41..4792abdffb8 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs @@ -21,7 +21,7 @@ public Client() public void Run() { System.ServiceModel.Channels.Binding binding = new CustomBinding(); - EndpointAddress address = new EndpointAddress("http://localhost:8080/DuplexHello"); + EndpointAddress address = new("http://localhost:8080/DuplexHello"); SampleDuplexHelloClient wcfClient = new SampleDuplexHelloClient(new InstanceContext(this), binding, address); try diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs index 11a035f29a2..2fb7f5fa76a 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs @@ -16,7 +16,7 @@ public static void Main() WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message); EndpointAddress address = new EndpointAddress("http://localhost:8080/ServiceMetadata/SampleService"); ChannelFactory factory - = new ChannelFactory(binding, address); + = new(binding, address); // Add the client side behavior programmatically to all created channels. factory.Endpoint.EndpointBehaviors.Add(new EndpointBehaviorMessageInspector()); From c4df5541625bfbba3d569a9d5519b15186848d45 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 3 Aug 2026 10:06:28 -0700 Subject: [PATCH 4/6] fix compile errors --- .../callbackbehaviorattribute/cs/client.slnx | 4 ++ .../callbackbehaviorattribute/cs/host.csproj | 44 +++++----------- .../cs/snippets.5000.json | 3 ++ .../channelfactorybehaviors/cs/client.slnx | 4 ++ .../channelfactorybehaviors/cs/host.csproj | 50 +++++-------------- .../cs/snippets.5000.json | 3 ++ 6 files changed, 40 insertions(+), 68 deletions(-) create mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx create mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json create mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx create mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx new file mode 100644 index 00000000000..03f56c1194f --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx @@ -0,0 +1,4 @@ + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj index 227ea09ff0d..aba85e0858f 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj @@ -1,44 +1,26 @@ - + - Debug - AnyCPU - {907F0C93-0FC2-4419-B0CE-2B775830A3C2} - Exe - false + net10.0 HostApplication Microsoft.WCF.Documentation + disable + disable + false - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - - - pdbonly - true - .\bin\Release\ - TRACE - - - - - - - - + + Always - - - - - \ No newline at end of file + + + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json new file mode 100644 index 00000000000..da9ebf8da2f --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json @@ -0,0 +1,3 @@ +{ + "host": "visualstudio" +} diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx new file mode 100644 index 00000000000..03f56c1194f --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx @@ -0,0 +1,4 @@ + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj index d8bbde4bae6..623b1723c42 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj @@ -1,51 +1,27 @@ - + - Debug - AnyCPU - {907F0C93-0FC2-4419-B0CE-2B775830A3C2} - Exe - false + net10.0 HostApplication Microsoft.WCF.Documentation - - - - - 3.5 + disable + disable + false - - true - full - false - .\bin\Debug\ - DEBUG;TRACE - - - pdbonly - true - .\bin\Release\ - TRACE - - - - - - - - - + + Always - - - - - \ No newline at end of file + + + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json new file mode 100644 index 00000000000..da9ebf8da2f --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json @@ -0,0 +1,3 @@ +{ + "host": "visualstudio" +} From a162f8e7e01bbeed9d0323c478b5591a0c71b122 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:29:51 -0700 Subject: [PATCH 5/6] remove two unneeded host projects --- .../callbackbehaviorattribute/cs/client.cs | 18 ++--- .../cs/client.csproj | 5 -- .../callbackbehaviorattribute/cs/client.slnx | 4 -- .../callbackbehaviorattribute/cs/host.csproj | 26 -------- .../cs/hostapplication.cs | 50 -------------- .../cs/hostapplication.exe.config | 30 --------- .../callbackbehaviorattribute/cs/services.cs | 55 ---------------- .../cs/snippets.5000.json | 3 - .../channelfactorybehaviors/cs/client.slnx | 4 -- .../channelfactorybehaviors/cs/host.csproj | 27 -------- .../cs/hostapplication.cs | 50 -------------- .../cs/hostapplication.exe.config | 50 -------------- .../cs/iendpointbehaviormessageinspector.cs | 65 ------------------- .../channelfactorybehaviors/cs/services.cs | 39 ----------- .../cs/snippets.5000.json | 3 - .../CallbackBehaviorAttribute.xml | 54 ++++++++------- xml/System.ServiceModel/ClientBase`1.xml | 4 +- .../DuplexClientBase`1.xml | 2 +- 18 files changed, 42 insertions(+), 447 deletions(-) delete mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx delete mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj delete mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.cs delete mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.exe.config delete mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/services.cs delete mode 100644 snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.cs delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.exe.config delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/services.cs delete mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs index 4792abdffb8..963b08f562f 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs @@ -6,6 +6,7 @@ namespace Microsoft.WCF.Documentation { + // [CallbackBehaviorAttribute( UseSynchronizationContext=true )] @@ -20,19 +21,19 @@ public Client() public void Run() { - System.ServiceModel.Channels.Binding binding = new CustomBinding(); + Binding binding = new CustomBinding(); EndpointAddress address = new("http://localhost:8080/DuplexHello"); SampleDuplexHelloClient wcfClient - = new SampleDuplexHelloClient(new InstanceContext(this), binding, address); + = new(new InstanceContext(this), binding, address); try { Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("Enter a greeting to send and press ENTER: "); + Console.WriteLine("Enter a greeting to send and press 'Enter': "); Console.Write(">>> "); Console.ForegroundColor = ConsoleColor.Green; string greeting = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("Called service with: \r\n\t" + greeting); + Console.WriteLine($"Called service with: \r\n\t{greeting}"); wcfClient.Hello(greeting); Console.WriteLine("Execution passes service call and moves to the WaitHandle."); this.waitHandle.WaitOne(); @@ -47,27 +48,28 @@ SampleDuplexHelloClient wcfClient } catch (TimeoutException timeProblem) { - Console.WriteLine("The service operation timed out. " + timeProblem.Message); + Console.WriteLine($"The service operation timed out. {timeProblem.Message}"); Console.ReadLine(); } catch (CommunicationException commProblem) { - Console.WriteLine("There was a communication problem. " + commProblem.Message); + Console.WriteLine($"There was a communication problem. {commProblem.Message}"); Console.ReadLine(); } } public static void Main() { - Client client = new Client(); + Client client = new(); client.Run(); } public void Reply(string response) { Console.WriteLine("Received output."); - Console.WriteLine("\r\n\t" + response); + Console.WriteLine($"\r\n\t{response}"); this.waitHandle.Set(); } } + // } // diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj index 08a5e8332c2..80f9cd11c5e 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj @@ -9,11 +9,6 @@ false - - - - - Always diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx deleted file mode 100644 index 03f56c1194f..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.slnx +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj deleted file mode 100644 index aba85e0858f..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/host.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - net10.0 - HostApplication - Microsoft.WCF.Documentation - disable - disable - false - - - - - - - - - - Always - - - - - - - - diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.cs b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.cs deleted file mode 100644 index 835953b2f2a..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Configuration; -using System.Collections.Generic; -using System.ServiceModel; -using System.Text; - -namespace Microsoft.WCF.Documentation -{ - class HostApplication - { - - static void Main() - { - HostApplication app = new HostApplication(); - app.Run(); - } - - private void Run() - { - // Create a ServiceHost for the service type and use the base address from configuration. - using (ServiceHost serviceHost = new ServiceHost(typeof(DuplexHello))) - { - try - { - // Open the ServiceHostBase to create listeners and start listening for messages. - serviceHost.Open(); - - // The service can now be accessed. - Console.WriteLine("The service is ready."); - Console.WriteLine("Press to terminate service."); - Console.WriteLine(); - Console.ReadLine(); - - // Close the ServiceHostBase to shutdown the service. - serviceHost.Close(); - } - catch (TimeoutException timeProblem) - { - Console.WriteLine("The service operation timed out. " + timeProblem.Message); - Console.Read(); - } - catch (CommunicationException commProblem) - { - Console.WriteLine("There was a communication problem. " + commProblem.Message); - Console.Read(); - } - } - } - } -} diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.exe.config b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.exe.config deleted file mode 100644 index 3b38b7adbe6..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/hostapplication.exe.config +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/services.cs b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/services.cs deleted file mode 100644 index cdb2a98e818..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/services.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -using System; -using System.Collections.Generic; -using System.ServiceModel; -using System.Threading; - -namespace Microsoft.WCF.Documentation -{ - [ServiceContract( - Name = "SampleDuplexHello", - Namespace = "http://microsoft.wcf.documentation", - CallbackContract = typeof(IHelloCallbackContract), - SessionMode = SessionMode.Required - )] - public interface IDuplexHello - { - [OperationContract(IsOneWay = true)] - void Hello(string greeting); - } - - public interface IHelloCallbackContract - { - [OperationContract(IsOneWay = true)] - void Reply(string responseToGreeting); - } - - public class DuplexHello : IDuplexHello - { - - public DuplexHello() - { - Console.WriteLine("Service object created: " + this.GetHashCode().ToString()); - } - - ~DuplexHello() - { - Console.WriteLine("Service object destroyed: " + this.GetHashCode().ToString()); - } - - public void Hello(string greeting) - { - Console.WriteLine("Caller sent: " + greeting); - Console.WriteLine("Session ID: " + OperationContext.Current.SessionId); - Console.WriteLine("Waiting two seconds before returning call."); - // Put a slight delay to demonstrate asynchronous behavior on client. - Thread.Sleep(2000); - IHelloCallbackContract callerProxy - = OperationContext.Current.GetCallbackChannel(); - string response = "Service object " + this.GetHashCode().ToString() + " received: " + greeting; - Console.WriteLine("Sending back: " + response); - callerProxy.Reply(response); - } - } -} -// diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json deleted file mode 100644 index da9ebf8da2f..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/snippets.5000.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "host": "visualstudio" -} diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx deleted file mode 100644 index 03f56c1194f..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.slnx +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj deleted file mode 100644 index 623b1723c42..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/host.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - net10.0 - HostApplication - Microsoft.WCF.Documentation - disable - disable - false - - - - - - - - - - - Always - - - - - - - - diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.cs deleted file mode 100644 index 1ccef0630d5..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Configuration; -using System.Collections.Generic; -using System.ServiceModel; -using System.Text; - -namespace Microsoft.WCF.Documentation -{ - class HostApplication - { - - static void Main() - { - HostApplication app = new HostApplication(); - app.Run(); - } - - private void Run() - { - // Create a ServiceHost for the service type and use the base address from configuration. - using (ServiceHost serviceHost = new ServiceHost(typeof(SampleService))) - { - try - { - // Open the ServiceHostBase to create listeners and start listening for messages. - serviceHost.Open(); - - // The service can now be accessed. - Console.WriteLine("The service is ready."); - Console.WriteLine("Press to terminate service."); - Console.WriteLine(); - Console.ReadLine(); - - // Close the ServiceHostBase to shutdown the service. - serviceHost.Close(); - } - catch (TimeoutException timeProblem) - { - Console.WriteLine("The service operation timed out. " + timeProblem.Message); - Console.Read(); - } - catch (CommunicationException commProblem) - { - Console.WriteLine("There was a communication problem. " + commProblem.Message); - Console.Read(); - } - } - } - } -} diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.exe.config b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.exe.config deleted file mode 100644 index 6e49f0b25df..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/hostapplication.exe.config +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs deleted file mode 100644 index 9e79164560d..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs +++ /dev/null @@ -1,65 +0,0 @@ - -// -using System; -using System.Collections.Generic; -using System.ServiceModel; -using System.ServiceModel.Description; -using System.ServiceModel.Dispatcher; -using System.Text; - -namespace Microsoft.WCF.Documentation -{ - class EndpointBehaviorMessageInspector : IEndpointBehavior, IClientMessageInspector - { - // - // IEndpointBehavior Members - public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) - { - return; - } - - public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior) - { - behavior.ClientMessageInspectors.Add(new EndpointBehaviorMessageInspector()); - } - - public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher) - { - return; - } - - public void Validate(ServiceEndpoint serviceEndpoint) - { - return; - } - // - - // - // Sample helper for creating the behavior instance in modern .NET builds. - public static EndpointBehaviorMessageInspector CreateBehavior() - { - return new EndpointBehaviorMessageInspector(); - } - // - - // - // IClientMessageInspector members - // - - #region IClientMessageInspector Members - - public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) - { - Console.WriteLine("AfterReceiveReply called."); - } - - public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) - { - Console.WriteLine("BeforeSendRequest called."); - return null; - } - - #endregion - } -} -// diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/services.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/services.cs deleted file mode 100644 index a7dc0b3f748..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/services.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; - -namespace Microsoft.WCF.Documentation -{ - [ServiceContractAttribute(Namespace="http://microsoft.wcf.documentation")] - public interface ISampleService{ - - [OperationContractAttribute] - [FaultContractAttribute(typeof(SampleFault))] - string SampleMethod(string msg); - } - - class SampleService : ISampleService - { - public string SampleMethod(string msg) - { - Console.WriteLine("The caller said: \"{0}\"", msg); - return "The service greets you: " + msg; - } - } - - // The detail type of the specified SOAP fault. - [DataContractAttribute(Namespace = "http://microsoft.wcf.documentation")] - public class SampleFault - { - [DataMemberAttribute(Name="FaultMessage")] - private string msg; - - public string FaultMessage - { - get { return this.msg; } - set { this.msg = value; } - } - } -} diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json deleted file mode 100644 index da9ebf8da2f..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/snippets.5000.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "host": "visualstudio" -} diff --git a/xml/System.ServiceModel/CallbackBehaviorAttribute.xml b/xml/System.ServiceModel/CallbackBehaviorAttribute.xml index 60db32f2fd9..c8c7a6eeb35 100644 --- a/xml/System.ServiceModel/CallbackBehaviorAttribute.xml +++ b/xml/System.ServiceModel/CallbackBehaviorAttribute.xml @@ -90,10 +90,12 @@ - The property informs the system whether it should confirm that SOAP headers marked as `MustUnderstand` have, in fact, been understood. - - ## Examples - The following code example shows a on a callback object that uses the object to determine which thread to marshal to, the property to enforce message validation, and the property to return exceptions as objects to the service for debugging purposes. + The following code example shows a on a callback object that uses: + + - The object to determine which thread to marshal to. + - The property to enforce message validation. + - And the property to return exceptions as objects to the service for debugging purposes. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: @@ -139,21 +141,18 @@ The default settings for the are: - The property is `true`. - - The is set to . - - The property is `false`. - -- is `false`. - -- is `false`. - +- is `false`. +- is `false`. - The property is `true`. - - ## Examples - The following code example shows a on a callback object that uses the object to determine which thread to marshal to, the property to enforce message validation, and the property to return exceptions as objects to the service for debugging purposes. + The following code example shows a on a callback object that uses: + + - The object to determine which thread to marshal to. + - The property to enforce message validation. + - And the property to return exceptions as objects to the service for debugging purposes. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: @@ -333,12 +332,14 @@ Set to `true` to enable exception information to flow back to services for debugging purposes when possible. This is a development-only feature and should not be employed in deployed services. These faults appear to the calling service as objects. > [!IMPORTANT] -> Setting to `true` enables services to obtain information about internal client callback exceptions; it is only recommended as a way of temporarily debugging a duplex client application. - - +> Setting to `true` enables services to obtain information about internal client callback exceptions; it is only recommended as a way of temporarily debugging a duplex client application. ## Examples - The following code example shows a on a callback object that uses the object to determine which thread to marshal to, the property to enforce message validation, and the property to return exceptions as objects to the service for debugging purposes. + The following code example shows a on a callback object that uses: + + - The object to determine which thread to marshal to. + - The property to enforce message validation. + - And the property to return exceptions as objects to the service for debugging purposes. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: @@ -667,14 +668,17 @@ is set to `true`, synchronizes all calls to the service to run on the user interface thread. - - Note that the thread used is the current synchronization thread when or is called. In the case of an Windows Forms application, this means that these calls should occur after a call to the method. +Use this property to provide the user interface thread affinity that some applications require. For example, a Windows Forms application may be registered as a singleton service object. In this case, all calls into the service must run on the Windows Forms thread. The default case, in which is set to `true`, synchronizes all calls to the service to run on the user interface thread. +The thread used is the current synchronization thread when or is called. In the case of an Windows Forms application, this means that these calls should occur after a call to the method. ## Examples - The following code example shows a on a callback object that uses the object to determine which thread to marshal to, the property to enforce message validation, and the property to return exceptions as objects to the service for debugging purposes. + The following code example shows a on a callback object that uses: + + - The object to determine which thread to marshal to. + - The property to enforce message validation. + - And the property to return exceptions as objects to the service for debugging purposes. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: @@ -714,10 +718,12 @@ ## Remarks Use the property to turn off the enforced validation of arriving message headers. In normal execution, message headers are compared against the property to confirm that arriving headers are explicitly handled by the callback object runtime. Set this to `false` to disable this checking. When set to `false`, the application must check for headers marked with MustUnderstand="true" and return a fault if one or more of them were not understood. This is useful when the callback is supposed to accept any incoming SOAP messages (for example, when using typed or untyped messages) and perform custom header processing. - - ## Examples - The following code example shows a on a callback object that uses the object to determine which thread to marshal to, the property to enforce message validation, and the property to return exceptions as objects to the service for debugging purposes. + The following code example shows a on a callback object that uses: + + - The object to determine which thread to marshal to. + - The property to enforce message validation. + - And the property to return exceptions as objects to the service for debugging purposes. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: diff --git a/xml/System.ServiceModel/ClientBase`1.xml b/xml/System.ServiceModel/ClientBase`1.xml index cf719e6f601..eadc02d4970 100644 --- a/xml/System.ServiceModel/ClientBase`1.xml +++ b/xml/System.ServiceModel/ClientBase`1.xml @@ -208,12 +208,10 @@ ## Remarks Use this constructor when the service contract requires a callback service instance. The target endpoint is constructed from the type parameter and information in the application configuration file. - - ## Examples The following code example shows how to use this constructor with a `SampleDuplexHelloClient` class to pass a callback object that listens for messages from the service. - :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: ]]> diff --git a/xml/System.ServiceModel/DuplexClientBase`1.xml b/xml/System.ServiceModel/DuplexClientBase`1.xml index 86baaf4d2ed..dbe2ca1ed3d 100644 --- a/xml/System.ServiceModel/DuplexClientBase`1.xml +++ b/xml/System.ServiceModel/DuplexClientBase`1.xml @@ -74,7 +74,7 @@ - Avoid finalizers; but if you include one, you should suppress the build warning and call and the finalizer itself from (On)(Begin)Close (and/or OnAbort) in order to emulate what would have been the auto-generated behavior. ## Examples - The following example shows the use in the client of a duplex WCF client type, the `SampleDuplexHelloClient`, to pass a new object with the callback object to listen for callbacks. + The following example shows how to use this type in the client of a duplex WCF client type (`SampleDuplexHelloClient`) to pass a new object with the callback object to listen for callbacks. :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.cs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/callbackbehaviorattribute/vb/client.vb" id="Snippet3"::: From c459882a919da8f7293c90c252ffaa35ac99c10b Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:50:46 -0700 Subject: [PATCH 6/6] fix compile errors --- .../cs/client.csproj | 1 - .../channelfactorybehaviors/cs/client.cs | 8 +-- .../channelfactorybehaviors/cs/client.csproj | 9 +-- .../cs/iendpointbehaviormessageinspector.cs | 63 +++++++++++++++++++ .../channelfactorybehaviors/cs/proxycode.cs | 13 ++-- 5 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs diff --git a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj index 80f9cd11c5e..32019b52155 100644 --- a/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj +++ b/snippets/csharp/VS_Snippets_CFX/callbackbehaviorattribute/cs/client.csproj @@ -6,7 +6,6 @@ Microsoft.WCF.Documentation disable disable - false diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs index 2fb7f5fa76a..c66864a2b38 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.cs @@ -1,9 +1,5 @@ using System; using System.ServiceModel; -using System.ServiceModel.Channels; - -using microsoft.wcf.documentation; -// for the client behavior using Microsoft.WCF.Documentation; // @@ -13,8 +9,8 @@ public static void Main() { try { - WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message); - EndpointAddress address = new EndpointAddress("http://localhost:8080/ServiceMetadata/SampleService"); + WSHttpBinding binding = new(SecurityMode.Message); + EndpointAddress address = new("http://localhost:8080/ServiceMetadata/SampleService"); ChannelFactory factory = new(binding, address); diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj index 17406f9fb48..d395bd39096 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/client.csproj @@ -6,22 +6,19 @@ Microsoft.WCF.Documentation disable disable - false {66190530-B4E3-4BF0-94B4-DFE52D15E50F} - - - - - + Always + + \ No newline at end of file diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs new file mode 100644 index 00000000000..5a3cedadf45 --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/iendpointbehaviormessageinspector.cs @@ -0,0 +1,63 @@ + +// +using System; +using System.ServiceModel; +using System.ServiceModel.Description; +using System.ServiceModel.Dispatcher; + +namespace Microsoft.WCF.Documentation +{ + class EndpointBehaviorMessageInspector : IEndpointBehavior, IClientMessageInspector + { + // + // IEndpointBehavior Members + public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) + { + return; + } + + public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime behavior) + { + behavior.ClientMessageInspectors.Add(new EndpointBehaviorMessageInspector()); + } + + public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatcher) + { + return; + } + + public void Validate(ServiceEndpoint serviceEndpoint) + { + return; + } + // + + // + // Sample helper for creating the behavior instance in modern .NET builds. + public static EndpointBehaviorMessageInspector CreateBehavior() + { + return new EndpointBehaviorMessageInspector(); + } + // + + // + // IClientMessageInspector members + // + + #region IClientMessageInspector Members + + public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) + { + Console.WriteLine("AfterReceiveReply called."); + } + + public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) + { + Console.WriteLine("BeforeSendRequest called."); + return null; + } + + #endregion + } +} +// diff --git a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs index 94445685d51..4ea16a9dbf4 100644 --- a/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs +++ b/snippets/csharp/VS_Snippets_CFX/channelfactorybehaviors/cs/proxycode.cs @@ -8,16 +8,17 @@ // //------------------------------------------------------------------------------ +using Microsoft.WCF.Documentation; + [assembly: System.Runtime.Serialization.ContractNamespaceAttribute("http://microsoft.wcf.documentation", ClrNamespace="microsoft.wcf.documentation")] -namespace microsoft.wcf.documentation +namespace Microsoft.WCF.Documentation { using System.Runtime.Serialization; - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")] [System.Runtime.Serialization.DataContractAttribute()] - public partial class SampleFault : object, System.Runtime.Serialization.IExtensibleDataObject + public partial class SampleFault : object, IExtensibleDataObject { private System.Runtime.Serialization.ExtensionDataObject extensionDataField; @@ -51,14 +52,12 @@ public string FaultMessage } } - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] [System.ServiceModel.ServiceContractAttribute(Namespace="http://microsoft.wcf.documentation")] public interface ISampleService { - [System.ServiceModel.OperationContractAttribute(Action="http://microsoft.wcf.documentation/ISampleService/SampleMethod", ReplyAction="http://microsoft.wcf.documentation/ISampleService/SampleMethodResponse")] - [System.ServiceModel.FaultContractAttribute(typeof(microsoft.wcf.documentation.SampleFault), Action="http://microsoft.wcf.documentation/ISampleService/SampleMethodSampleFaultFault")] + [System.ServiceModel.FaultContractAttribute(typeof(SampleFault), Action="http://microsoft.wcf.documentation/ISampleService/SampleMethodSampleFaultFault")] string SampleMethod(string msg); } @@ -70,12 +69,10 @@ public interface ISampleServiceChannel : ISampleService, System.ServiceModel.ICl [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public partial class SampleServiceClient : System.ServiceModel.ClientBase, ISampleService { - public SampleServiceClient() { } - public SampleServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) {