Skip to content

Commit fef8d69

Browse files
committed
override client binding and set Security Mode to transport
1 parent b9a9523 commit fef8d69

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Basic/Binding/Net/Tcp/Default/Client/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
CalculatorServiceClient client = new CalculatorServiceClient();
4+
using System.ServiceModel;
5+
6+
// there is an issue in client code generation where the Security.Mode = None
7+
// override client binding with Transport Security Mode to match service definition
8+
NetTcpBinding binding = new NetTcpBinding();
9+
var endpointAddress = new EndpointAddress("net.tcp://localhost:8089/CalculatorService/netTcp");
10+
11+
CalculatorServiceClient client = new CalculatorServiceClient(binding, endpointAddress);
512

613
// Call the Add service operation.
714
double value1 = 100.00D;
@@ -32,4 +39,4 @@
3239

3340
Console.WriteLine();
3441
Console.WriteLine("Press <ENTER> to terminate client.");
35-
Console.ReadLine();
42+
Console.ReadLine();

Basic/Binding/Net/Tcp/Default/Service/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
serviceOptions.BaseAddresses.Add(new Uri($"http://localhost:{HttpPort}/CalculatorService/netTcp"));
3131
})
3232
// Add NetTcpBinding endpoint
33-
.AddServiceEndpoint<CalculatorService, ICalculatorService>(new NetTcpBinding(SecurityMode.None), $"net.tcp://localhost:{NetTcpPort}/CalculatorService/netTcp");
33+
.AddServiceEndpoint<CalculatorService, ICalculatorService>(new NetTcpBinding(), $"net.tcp://localhost:{NetTcpPort}/CalculatorService/netTcp");
3434

3535
// Configure WSDL to be available
3636
var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();

0 commit comments

Comments
 (0)