Skip to content

Commit f424f6f

Browse files
authored
Expose DuplexChannelFactory<TChannel> constructor with Type overloads (#5167)
* Public DuplexChannelFactory<TChannel> Ctor Type overloads * Add E2E test for DuplexChannelFactory Ctor with callbackServiceType overload.
1 parent b90ebc9 commit f424f6f

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/System.Private.ServiceModel/tests/Scenarios/Client/TypedClient/TypedProxyDuplexTests.4.1.0.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,39 @@ public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn()
5252
}
5353
}
5454
}
55+
56+
[WcfFact]
57+
[OuterLoop]
58+
public static void DuplexChanelFactory_Ctor_Type_Overload_E2E()
59+
{
60+
DuplexChannelFactory<IWcfDuplexTaskReturnService> factory = null;
61+
Guid guid = Guid.NewGuid();
62+
63+
NetTcpBinding binding = new NetTcpBinding();
64+
binding.Security.Mode = SecurityMode.None;
65+
66+
DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback();
67+
InstanceContext context = new InstanceContext(callbackService);
68+
69+
try
70+
{
71+
factory = new DuplexChannelFactory<IWcfDuplexTaskReturnService>(typeof(DuplexTaskReturnServiceCallback), binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address));
72+
IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel(context);
73+
74+
Task<Guid> task = serviceProxy.Ping(guid);
75+
76+
Guid returnedGuid = task.Result;
77+
78+
Assert.Equal(guid, returnedGuid);
79+
80+
factory.Close();
81+
}
82+
finally
83+
{
84+
if (factory != null && factory.State != CommunicationState.Closed)
85+
{
86+
factory.Abort();
87+
}
88+
}
89+
}
5590
}

src/System.ServiceModel.Primitives/ref/System.ServiceModel.Duplex.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public enum ConcurrencyMode
2828
}
2929
public partial class DuplexChannelFactory<TChannel> : System.ServiceModel.ChannelFactory<TChannel>
3030
{
31+
public DuplexChannelFactory(Type callbackInstanceType) : base(default(System.Type)) { }
32+
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Channels.Binding binding) : base(default(System.Type)) { }
33+
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(default(System.Type)) { }
34+
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Channels.Binding binding, string remoteAddress) : base(default(System.Type)) { }
35+
public DuplexChannelFactory(Type callbackInstanceType, System.ServiceModel.Description.ServiceEndpoint serviceEndpoint) : base(default(System.Type)) { }
3136
public DuplexChannelFactory(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding) : base(default(System.Type)) { }
3237
public DuplexChannelFactory(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(default(System.Type)) { }
3338
public DuplexChannelFactory(System.ServiceModel.InstanceContext callbackInstance, System.ServiceModel.Channels.Binding binding, string remoteAddress) : base(default(System.Type)) { }

src/System.ServiceModel.Primitives/tests/ServiceModel/DuplexChannelFactoryTest.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reflection;
88
using System.ServiceModel;
99
using System.ServiceModel.Channels;
10+
using System.ServiceModel.Description;
1011
using Infrastructure.Common;
1112
using Xunit;
1213

@@ -148,6 +149,39 @@ public static void CreateChannel_Using_NetTcpBinding_Defaults()
148149
Assert.NotNull(proxy);
149150
}
150151

152+
[WcfFact]
153+
public static void Ctor_Type_Overloads_Can_CreateChannel()
154+
{
155+
Binding binding = new NetTcpBinding();
156+
string remoteAddress = "net.tcp://not-an-endpoint";
157+
EndpointAddress endpoint = new EndpointAddress(remoteAddress);
158+
ServiceEndpoint serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IWcfDuplexService)), binding, endpoint);
159+
WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
160+
InstanceContext context = new InstanceContext(callback);
161+
162+
DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), binding, endpoint);
163+
IWcfDuplexService proxy = factory.CreateChannel(context);
164+
Assert.NotNull(proxy);
165+
166+
factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), binding, remoteAddress);
167+
proxy = factory.CreateChannel(context);
168+
Assert.NotNull(proxy);
169+
170+
factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), binding);
171+
proxy = factory.CreateChannel(context, endpoint);
172+
Assert.NotNull(proxy);
173+
174+
factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback));
175+
factory.Endpoint.Binding = binding;
176+
factory.Endpoint.Address = endpoint;
177+
proxy = factory.CreateChannel(context);
178+
Assert.NotNull(proxy);
179+
180+
factory = new DuplexChannelFactory<IWcfDuplexService>(typeof(WcfDuplexServiceCallback), serviceEndpoint);
181+
proxy = factory.CreateChannel(context);
182+
Assert.NotNull(proxy);
183+
}
184+
151185
[WcfFact]
152186
public static void CreateChannel_Using_NetTcp_NoSecurity()
153187
{

0 commit comments

Comments
 (0)