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

Fix OneWay only contracts with ReliableSessions #4395

Merged
merged 1 commit into from
Oct 15, 2020
Merged
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 @@ -330,6 +330,26 @@ protected override void OnOpen(TimeSpan timeout)
CommunicationObjectInternal.OnOpen(this, timeout);
}

protected internal override async Task OnOpenAsync(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
bool throwing = true;

try
{
await _binder.OpenAsync(timeoutHelper.RemainingTime());
await _session.OpenAsync(timeoutHelper.RemainingTime());
throwing = false;
}
finally
{
if (throwing)
{
await Binder.CloseAsync(timeoutHelper.RemainingTime());
}
}
}

protected override async Task OnSendAsync(Message message, TimeSpan timeout)
{
if (!await Connection.AddMessageAsync(message, timeout, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,21 @@ public static string ReliableSession_NetHttp
get { return GetEndpointAddress("ReliableSessionService.svc/NetHttp"); }
}

public static string ReliableOneWaySession_NetHttp
{
get { return GetEndpointAddress("ReliableSessionOneWayService.svc/NetHttp"); }
}

public static string ReliableSession_WSHttp
{
get { return GetEndpointAddress("ReliableSessionService.svc/WSHttp"); }
}

public static string ReliableOneWaySession_WSHttp
{
get { return GetEndpointAddress("ReliableSessionOneWayService.svc/WSHttp"); }
}

#region WebSocket Addresses
public static string HttpBaseAddress_NetHttpWebSockets
{
Expand Down Expand Up @@ -734,6 +744,11 @@ public static string ReliableSession_NetTcp
get { return GetEndpointAddress("ReliableSessionService.svc/NetTcp", protocol: "net.tcp"); }
}

public static string ReliableOneWaySession_NetTcp
{
get { return GetEndpointAddress("ReliableSessionOneWayService.svc/NetTcp", protocol: "net.tcp"); }
}

public static string ReliableDuplexSession_NetTcp
{
get { return GetEndpointAddress("ReliableSessionDuplexService.svc/NetTcp", protocol: "net.tcp"); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,13 @@ public interface IWcfReliableService
Task<string> EchoAsync(string echo);
}

[ServiceContract]
public interface IOneWayWcfReliableService
{
[OperationContract(IsOneWay = true)]
Task OneWayAsync(string text);
}

[ServiceContract(CallbackContract = typeof(IWcfReliableDuplexService))]
public interface IWcfReliableDuplexService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,43 @@ public static async Task EchoCall(ReliableMessagingVersion rmVersion, bool order
}
}

[WcfTheory]
[MemberData(nameof(GetTestVariations))]
[OuterLoop]
public static async Task OneWayCall(ReliableMessagingVersion rmVersion, bool ordered, string endpointSuffix)
{
string testString = "Hello";
ChannelFactory<IOneWayWcfReliableService> factory = null;
IOneWayWcfReliableService serviceProxy = null;
NetHttpBinding binding = null;

try
{
// *** SETUP *** \\
binding = new NetHttpBinding(BasicHttpSecurityMode.None, true);
binding.ReliableSession.Ordered = ordered;
var customBinding = new CustomBinding(binding);
var reliableSessionBindingElement = customBinding.Elements.Find<ReliableSessionBindingElement>();
reliableSessionBindingElement.ReliableMessagingVersion = rmVersion;
factory = new ChannelFactory<IOneWayWcfReliableService>(customBinding, new EndpointAddress(Endpoints.ReliableOneWaySession_NetHttp + endpointSuffix));
serviceProxy = factory.CreateChannel();
// *** EXECUTE *** \\
((IClientChannel)serviceProxy).Open(); // This will establish a reliable session
await serviceProxy.OneWayAsync(testString);
// *** VALIDATE *** \\

// *** CLEANUP *** \\
((IClientChannel)serviceProxy).Close();
factory.Close();
((ICommunicationObject)serviceProxy).Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}

[WcfTheory]
[MemberData(nameof(GetTestVariations))]
[OuterLoop]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ public static async Task EchoCall(ReliableMessagingVersion rmVersion, bool order
}
}

[WcfTheory]
[MemberData(nameof(GetTestVariations))]
[OuterLoop]
public static async Task OneWayCall(ReliableMessagingVersion rmVersion, bool ordered, string endpointSuffix)
{
string testString = "Hello";
ChannelFactory<IOneWayWcfReliableService> factory = null;
IOneWayWcfReliableService serviceProxy = null;
NetTcpBinding binding = null;

try
{
// *** SETUP *** \\
binding = new NetTcpBinding(SecurityMode.None, true);
binding.ReliableSession.Ordered = ordered;
var customBinding = new CustomBinding(binding);
var reliableSessionBindingElement = customBinding.Elements.Find<ReliableSessionBindingElement>();
reliableSessionBindingElement.ReliableMessagingVersion = rmVersion;
factory = new ChannelFactory<IOneWayWcfReliableService>(customBinding, new EndpointAddress(Endpoints.ReliableOneWaySession_NetTcp + endpointSuffix));
serviceProxy = factory.CreateChannel();
// *** EXECUTE *** \\
((IClientChannel)serviceProxy).Open(); // This will establish a reliable session
await serviceProxy.OneWayAsync(testString);
// *** VALIDATE *** \\

// *** CLEANUP *** \\
((IClientChannel)serviceProxy).Close();
factory.Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}

[WcfTheory]
[MemberData(nameof(GetTestVariations))]
[OuterLoop]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,43 @@ public static async Task EchoCall(ReliableMessagingVersion rmVersion, bool order
}
}

[WcfTheory]
[MemberData(nameof(GetTestVariations))]
[OuterLoop]
public static async Task OneWayCall(ReliableMessagingVersion rmVersion, bool ordered, string endpointSuffix)
{
string testString = "Hello";
ChannelFactory<IOneWayWcfReliableService> factory = null;
IOneWayWcfReliableService serviceProxy = null;
WSHttpBinding binding = null;

try
{
// *** SETUP *** \\
binding = new WSHttpBinding(SecurityMode.None, true);
binding.ReliableSession.Ordered = ordered;
var customBinding = new CustomBinding(binding);
var reliableSessionBindingElement = customBinding.Elements.Find<ReliableSessionBindingElement>();
reliableSessionBindingElement.ReliableMessagingVersion = rmVersion;
factory = new ChannelFactory<IOneWayWcfReliableService>(customBinding, new EndpointAddress(Endpoints.ReliableOneWaySession_WSHttp + endpointSuffix));
serviceProxy = factory.CreateChannel();
// *** EXECUTE *** \\
((IClientChannel)serviceProxy).Open(); // This will establish a reliable session
await serviceProxy.OneWayAsync(testString);
// *** VALIDATE *** \\

// *** CLEANUP *** \\
((IClientChannel)serviceProxy).Close();
factory.Close();
((ICommunicationObject)serviceProxy).Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}

[WcfTheory]
[MemberData(nameof(GetTestVariations))]
[OuterLoop]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public interface IWcfReliableService
string Echo(string echo);
}

[ServiceContract]
public interface IOneWayWcfReliableService
{
[OperationContract(IsOneWay = true)]
void OneWay(string text);
}

[ServiceContract(CallbackContract = typeof(IWcfReliableDuplexService))]
public interface IWcfReliableDuplexService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace WcfService
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
public class WcfReliableService : IWcfReliableService, IWcfReliableDuplexService
public class WcfReliableService : IWcfReliableService, IWcfReliableDuplexService, IOneWayWcfReliableService
{
private int _currentNumber = 0;

Expand All @@ -27,5 +27,10 @@ public string DuplexEcho(string echo)
var callback = OperationContext.Current.GetCallbackChannel<IWcfReliableDuplexService>();
return callback.DuplexEcho(echo);
}

public void OneWay(string text)
{
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace WcfService
{
[TestServiceDefinition(BasePath = "ReliableSessionDuplexService.svc", Schema = ServiceSchema.NETTCP)]
public class ReliableSessionDuplexSerivceHost : TestServiceHostBase<IWcfReliableDuplexService>
public class ReliableSessionDuplexServiceHost : TestServiceHostBase<IWcfReliableDuplexService>
{
protected override IList<Binding> GetBindings()
{
Expand All @@ -37,7 +37,7 @@ private void AddBinding(List<Binding> bindingList, Binding binding, bool ordered
bindingList.Add(customBinding);
}

public ReliableSessionDuplexSerivceHost(params Uri[] baseAddresses)
public ReliableSessionDuplexServiceHost(params Uri[] baseAddresses)
: base(typeof(WcfReliableService), baseAddresses)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace WcfService
{
[TestServiceDefinition(BasePath = "ReliableSessionOneWayService.svc", Schema = ServiceSchema.HTTP | ServiceSchema.NETTCP)]
public class ReliableSessionOneWaySerivceHost : TestServiceHostBase<IOneWayWcfReliableService>
{
protected override IList<Binding> GetBindings()
{
var bindings = new List<Binding>();
AddBindings(bindings, new NetHttpBinding(BasicHttpSecurityMode.None, true), "NetHttp");
AddBindings(bindings, new NetTcpBinding(SecurityMode.None, true), "NetTcp");
AddBindings(bindings, new WSHttpBinding(SecurityMode.None, true), "WSHttp");
return bindings;
}

private void AddBindings(List<Binding> bindingList, Binding binding, string baseName)
{
AddBinding(bindingList, binding, true, ReliableMessagingVersion.WSReliableMessaging11, baseName);
AddBinding(bindingList, binding, false, ReliableMessagingVersion.WSReliableMessaging11, baseName);
AddBinding(bindingList, binding, true, ReliableMessagingVersion.WSReliableMessagingFebruary2005, baseName);
AddBinding(bindingList, binding, false, ReliableMessagingVersion.WSReliableMessagingFebruary2005, baseName);
}

private void AddBinding(List<Binding> bindingList, Binding binding, bool ordered, ReliableMessagingVersion rmVersion, string baseName)
{
var customBinding = new CustomBinding(binding);
var reliableSessionBindingElement = customBinding.Elements.Find<ReliableSessionBindingElement>();
reliableSessionBindingElement.Ordered = ordered;
reliableSessionBindingElement.ReliableMessagingVersion = rmVersion;
customBinding.Name = baseName + (ordered ? "Ordered" : "Unordered") + "_" + rmVersion.ToString();
bindingList.Add(customBinding);
}

public ReliableSessionOneWaySerivceHost(params Uri[] baseAddresses)
: base(typeof(WcfReliableService), baseAddresses)
{
}
}
}