Skip to content

Commit

Permalink
Expose DuplexChannelFactory<TChannel> constructor with Type overloads (
Browse files Browse the repository at this point in the history
…#5167)

* Public DuplexChannelFactory<TChannel> Ctor Type overloads

* Add E2E test for DuplexChannelFactory Ctor with callbackServiceType overload.
  • Loading branch information
imcarolwang authored Jul 3, 2023
1 parent b90ebc9 commit f424f6f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,39 @@ public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn()
}
}
}

[WcfFact]
[OuterLoop]
public static void DuplexChanelFactory_Ctor_Type_Overload_E2E()
{
DuplexChannelFactory<IWcfDuplexTaskReturnService> factory = null;
Guid guid = Guid.NewGuid();

NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;

DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback();
InstanceContext context = new InstanceContext(callbackService);

try
{
factory = new DuplexChannelFactory<IWcfDuplexTaskReturnService>(typeof(DuplexTaskReturnServiceCallback), binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address));
IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel(context);

Task<Guid> task = serviceProxy.Ping(guid);

Guid returnedGuid = task.Result;

Assert.Equal(guid, returnedGuid);

factory.Close();
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public enum ConcurrencyMode
}
public partial class DuplexChannelFactory<TChannel> : System.ServiceModel.ChannelFactory<TChannel>
{
public DuplexChannelFactory(Type callbackInstanceType) : base(default(System.Type)) { }
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Channels.Binding binding) : base(default(System.Type)) { }
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(default(System.Type)) { }
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Channels.Binding binding, string remoteAddress) : base(default(System.Type)) { }
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Description.ServiceEndpoint serviceEndpoint) : base(default(System.Type)) { }
public DuplexChannelFactory(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding) : base(default(System.Type)) { }
public DuplexChannelFactory(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(default(System.Type)) { }
public DuplexChannelFactory(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, string remoteAddress) : base(default(System.Type)) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using Infrastructure.Common;
using Xunit;

Expand Down Expand Up @@ -148,6 +149,39 @@ public static void CreateChannel_Using_NetTcpBinding_Defaults()
Assert.NotNull(proxy);
}

[WcfFact]
public static void Ctor_Type_Overloads_Can_CreateChannel()
{
Binding binding = new NetTcpBinding();
string remoteAddress = "net.tcp://not-an-endpoint";
EndpointAddress endpoint = new EndpointAddress(remoteAddress);
ServiceEndpoint serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IWcfDuplexService)), binding, endpoint);
WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
InstanceContext context = new InstanceContext(callback);

DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), binding, endpoint);
IWcfDuplexService proxy = factory.CreateChannel(context);
Assert.NotNull(proxy);

factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), binding, remoteAddress);
proxy = factory.CreateChannel(context);
Assert.NotNull(proxy);

factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), binding);
proxy = factory.CreateChannel(context, endpoint);
Assert.NotNull(proxy);

factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback));
factory.Endpoint.Binding = binding;
factory.Endpoint.Address = endpoint;
proxy = factory.CreateChannel(context);
Assert.NotNull(proxy);

factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), serviceEndpoint);
proxy = factory.CreateChannel(context);
Assert.NotNull(proxy);
}

[WcfFact]
public static void CreateChannel_Using_NetTcp_NoSecurity()
{
Expand Down

0 comments on commit f424f6f

Please sign in to comment.