1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.Remoting;
using System.Security;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Diagnostics;
using System.ServiceModel.Dispatcher;
abstract class ServiceChannelFactory : ChannelFactoryBase
{
string bindingName;
List<IChannel> channelsList;
ClientRuntime clientRuntime;
RequestReplyCorrelator requestReplyCorrelator = new RequestReplyCorrelator();
IDefaultCommunicationTimeouts timeouts;
MessageVersion messageVersion;
public ServiceChannelFactory(ClientRuntime clientRuntime, Binding binding)
: base()
{
if (clientRuntime == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("clientRuntime");
}
this.bindingName = binding.Name;
this.channelsList = new List<IChannel>();
this.clientRuntime = clientRuntime;
this.timeouts = new DefaultCommunicationTimeouts(binding);
this.messageVersion = binding.MessageVersion;
}
public ClientRuntime ClientRuntime
{
get
{
this.ThrowIfDisposed();
return this.clientRuntime;
}
}
internal RequestReplyCorrelator RequestReplyCorrelator
{
get
{
ThrowIfDisposed();
return this.requestReplyCorrelator;
}
}
protected override TimeSpan DefaultCloseTimeout
{
get { return this.timeouts.CloseTimeout; }
}
protected override TimeSpan DefaultReceiveTimeout
{
get { return this.timeouts.ReceiveTimeout; }
}
protected override TimeSpan DefaultOpenTimeout
{
get { return this.timeouts.OpenTimeout; }
}
protected override TimeSpan DefaultSendTimeout
{
get { return this.timeouts.SendTimeout; }
}
public MessageVersion MessageVersion
{
get { return this.messageVersion; }
}
// special overload for security only
public static ServiceChannelFactory BuildChannelFactory(ChannelBuilder channelBuilder, ClientRuntime clientRuntime)
{
if (channelBuilder.CanBuildChannelFactory<IDuplexChannel>())
{
return new ServiceChannelFactoryOverDuplex(channelBuilder.BuildChannelFactory<IDuplexChannel>(), clientRuntime,
channelBuilder.Binding);
}
else if (channelBuilder.CanBuildChannelFactory<IDuplexSessionChannel>())
{
return new ServiceChannelFactoryOverDuplexSession(channelBuilder.BuildChannelFactory<IDuplexSessionChannel>(), clientRuntime, channelBuilder.Binding, false);
}
else
{
return new ServiceChannelFactoryOverRequestSession(channelBuilder.BuildChannelFactory<IRequestSessionChannel>(), clientRuntime, channelBuilder.Binding, false);
}
}
public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint)
{
return BuildChannelFactory(serviceEndpoint, false);
}
public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose)
{
if (serviceEndpoint == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint");
}
serviceEndpoint.EnsureInvariants();
serviceEndpoint.ValidateForClient();
ChannelRequirements requirements;
ContractDescription contractDescription = serviceEndpoint.Contract;
ChannelRequirements.ComputeContractRequirements(contractDescription, out requirements);
BindingParameterCollection parameters;
ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters);
Binding binding = serviceEndpoint.Binding;
Type[] requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements);
CustomBinding customBinding = new CustomBinding(binding);
BindingContext context = new BindingContext(customBinding, parameters);
InternalDuplexBindingElement internalDuplexBindingElement = null;
InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement);
customBinding = new CustomBinding(context.RemainingBindingElements);
customBinding.CopyTimeouts(serviceEndpoint.Binding);
foreach (Type type in requiredChannels)
{
if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory<IOutputChannel>(parameters))
{
return new ServiceChannelFactoryOverOutput(customBinding.BuildChannelFactory<IOutputChannel>(parameters), clientRuntime, binding);
}
if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory<IRequestChannel>(parameters))
{
return new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory<IRequestChannel>(parameters), clientRuntime, binding);
}
if (type == typeof(IDuplexChannel) && customBinding.CanBuildChannelFactory<IDuplexChannel>(parameters))
{
if (requirements.usesReply &&
binding.CreateBindingElements().Find<TransportBindingElement>().ManualAddressing)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
SR.GetString(SR.CantCreateChannelWithManualAddressing)));
}
return new ServiceChannelFactoryOverDuplex(customBinding.BuildChannelFactory<IDuplexChannel>(parameters), clientRuntime, binding);
}
if (type == typeof(IOutputSessionChannel) && customBinding.CanBuildChannelFactory<IOutputSessionChannel>(parameters))
{
return new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory<IOutputSessionChannel>(parameters), clientRuntime, binding, false);
}
if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory<IRequestSessionChannel>(parameters))
{
return new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory<IRequestSessionChannel>(parameters), clientRuntime, binding, false);
}
if (type == typeof(IDuplexSessionChannel) && customBinding.CanBuildChannelFactory<IDuplexSessionChannel>(parameters))
{
if (requirements.usesReply &&
binding.CreateBindingElements().Find<TransportBindingElement>().ManualAddressing)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
SR.GetString(SR.CantCreateChannelWithManualAddressing)));
}
return new ServiceChannelFactoryOverDuplexSession(customBinding.BuildChannelFactory<IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose);
}
}
foreach (Type type in requiredChannels)
{
// For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well
if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory<IOutputSessionChannel>(parameters))
{
return new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory<IOutputSessionChannel>(parameters), clientRuntime, binding, true);
}
if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory<IRequestSessionChannel>(parameters))
{
return new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory<IRequestSessionChannel>(parameters), clientRuntime, binding, true);
}
// and for SessionMode.Required, it is possible that the InstanceContextProvider is handling the session management, so
// accept datagram variants if that is the case
if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory<IRequestChannel>(parameters)
&& customBinding.GetProperty<IContextSessionProvider>(parameters) != null)
{
return new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory<IRequestChannel>(parameters), clientRuntime, binding);
}
}
// we put a lot of work into creating a good error message, as this is a common case
Dictionary<Type, byte> supportedChannels = new Dictionary<Type, byte>();
if (customBinding.CanBuildChannelFactory<IOutputChannel>(parameters))
{
supportedChannels.Add(typeof(IOutputChannel), 0);
}
if (customBinding.CanBuildChannelFactory<IRequestChannel>(parameters))
{
supportedChannels.Add(typeof(IRequestChannel), 0);
}
if (customBinding.CanBuildChannelFactory<IDuplexChannel>(parameters))
{
supportedChannels.Add(typeof(IDuplexChannel), 0);
}
if (customBinding.CanBuildChannelFactory<IOutputSessionChannel>(parameters))
{
supportedChannels.Add(typeof(IOutputSessionChannel), 0);
}
if (customBinding.CanBuildChannelFactory<IRequestSessionChannel>(parameters))
{
supportedChannels.Add(typeof(IRequestSessionChannel), 0);
}
if (customBinding.CanBuildChannelFactory<IDuplexSessionChannel>(parameters))
{
supportedChannels.Add(typeof(IDuplexSessionChannel), 0);
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException(
supportedChannels.Keys, requiredChannels, binding.Name));
}
protected override void OnAbort()
{
IChannel channel = null;
lock (ThisLock)
{
channel = (channelsList.Count > 0) ? channelsList[channelsList.Count - 1] : null;
}
while (channel != null)
{
channel.Abort();
lock (ThisLock)
{
channelsList.Remove(channel);
channel = (channelsList.Count > 0) ? channelsList[channelsList.Count - 1] : null;
}
}
}
protected override void OnClose(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
while (true)
{
int count;
IChannel channel;
lock (ThisLock)
{
count = channelsList.Count;
if (count == 0)
return;
channel = channelsList[0];
}
channel.Close(timeoutHelper.RemainingTime());
}
}
protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
{
List<ICommunicationObject> objectList;
lock (ThisLock)
{
objectList = new List<ICommunicationObject>();
for (int index = 0; index < channelsList.Count; index++)
objectList.Add(channelsList[index]);
}
return new CloseCollectionAsyncResult(timeout, callback, state, objectList);
}
protected override void OnEndClose(IAsyncResult result)
{
CloseCollectionAsyncResult.End(result);
}
protected override void OnOpened()
{
base.OnOpened();
this.clientRuntime.LockDownProperties();
}
public void ChannelCreated(IChannel channel)
{
if (DiagnosticUtility.ShouldTraceVerbose)
{
TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.ChannelCreated,
SR.GetString(SR.TraceCodeChannelCreated, TraceUtility.CreateSourceString(channel)), this);
}
lock (ThisLock)
{
ThrowIfDisposed();
channelsList.Add(channel);
}
}
public void ChannelDisposed(IChannel channel)
{
if (DiagnosticUtility.ShouldTraceVerbose)
{
TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.ChannelDisposed,
SR.GetString(SR.TraceCodeChannelDisposed, TraceUtility.CreateSourceString(channel)),
this);
}
lock (ThisLock)
{
channelsList.Remove(channel);
}
}
public virtual ServiceChannel CreateServiceChannel(EndpointAddress address, Uri via)
{
IChannelBinder binder = this.CreateInnerChannelBinder(address, via);
ServiceChannel serviceChannel = new ServiceChannel(this, binder);
if (binder is DuplexChannelBinder)
{
DuplexChannelBinder duplexChannelBinder = binder as DuplexChannelBinder;
duplexChannelBinder.ChannelHandler = new ChannelHandler(this.messageVersion, binder, serviceChannel);
duplexChannelBinder.DefaultCloseTimeout = this.DefaultCloseTimeout;
duplexChannelBinder.DefaultSendTimeout = this.DefaultSendTimeout;
duplexChannelBinder.IdentityVerifier = this.clientRuntime.IdentityVerifier;
}
return serviceChannel;
}
public TChannel CreateChannel<TChannel>(EndpointAddress address)
{
return this.CreateChannel<TChannel>(address, null);
}
public TChannel CreateChannel<TChannel>(EndpointAddress address, Uri via)
{
if (!this.CanCreateChannel<TChannel>())
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
SR.GetString(SR.CouldnTCreateChannelForChannelType2, this.bindingName, typeof(TChannel).Name)));
}
return (TChannel)this.CreateChannel(typeof(TChannel), address, via);
}
public abstract bool CanCreateChannel<TChannel>();
public object CreateChannel(Type channelType, EndpointAddress address)
{
return this.CreateChannel(channelType, address, null);
}
public object CreateChannel(Type channelType, EndpointAddress address, Uri via)
{
if (via == null)
{
via = this.ClientRuntime.Via;
if (via == null)
{
via = address.Uri;
}
}
ServiceChannel serviceChannel = this.CreateServiceChannel(address, via);
serviceChannel.Proxy = CreateProxy(channelType, channelType, MessageDirection.Input, serviceChannel);
serviceChannel.ClientRuntime.GetRuntime().InitializeChannel((IClientChannel)serviceChannel.Proxy);
OperationContext current = OperationContext.Current;
if ((current != null) && (current.InstanceContext != null))
{
current.InstanceContext.WmiChannels.Add((IChannel)serviceChannel.Proxy);
serviceChannel.WmiInstanceContext = current.InstanceContext;
}
return serviceChannel.Proxy;
}
[Fx.Tag.SecurityNote(Critical = "Constructs a ServiceChannelProxy, which is Critical.",
Safe = "Returns the TP, but does not return the RealProxy -- caller can't get from TP to RP without an elevation.")]
[SecuritySafeCritical]
internal static object CreateProxy(Type interfaceType, Type proxiedType, MessageDirection direction, ServiceChannel serviceChannel)
{
if (!proxiedType.IsInterface)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString("SFxChannelFactoryTypeMustBeInterface")));
}
ServiceChannelProxy proxy = new ServiceChannelProxy(interfaceType, proxiedType, direction, serviceChannel);
return proxy.GetTransparentProxy();
}
[Fx.Tag.SecurityNote(Critical = "Calls LinkDemand method RemotingServices.GetRealProxy and access critical class ServiceChannelProxy.",
Safe = "Gets the ServiceChannel (which is not critical) and discards the RealProxy.")]
[SecuritySafeCritical]
internal static ServiceChannel GetServiceChannel(object transparentProxy)
{
IChannelBaseProxy cb = transparentProxy as IChannelBaseProxy;
if (cb != null)
return cb.GetServiceChannel();
ServiceChannelProxy proxy = RemotingServices.GetRealProxy(transparentProxy) as ServiceChannelProxy;
if (proxy != null)
return proxy.GetServiceChannel();
else
return null;
}
protected abstract IChannelBinder CreateInnerChannelBinder(EndpointAddress address, Uri via);
abstract class TypedServiceChannelFactory<TChannel> : ServiceChannelFactory
where TChannel : class, IChannel
{
IChannelFactory<TChannel> innerChannelFactory;
protected TypedServiceChannelFactory(IChannelFactory<TChannel> innerChannelFactory,
ClientRuntime clientRuntime, Binding binding)
: base(clientRuntime, binding)
{
this.innerChannelFactory = innerChannelFactory;
}
protected IChannelFactory<TChannel> InnerChannelFactory
{
get { return this.innerChannelFactory; }
}
protected override void OnAbort()
{
base.OnAbort();
this.innerChannelFactory.Abort();
}
protected override void OnOpen(TimeSpan timeout)
{
this.innerChannelFactory.Open(timeout);
}
protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
{
return this.innerChannelFactory.BeginOpen(timeout, callback, state);
}
protected override void OnEndOpen(IAsyncResult result)
{
this.innerChannelFactory.EndOpen(result);
}
protected override void OnClose(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
base.OnClose(timeoutHelper.RemainingTime());
this.innerChannelFactory.Close(timeoutHelper.RemainingTime());
}
protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
{
return new ChainedAsyncResult(timeout, callback, state, base.OnBeginClose, base.OnEndClose,
this.innerChannelFactory.BeginClose, this.innerChannelFactory.EndClose);
}
protected override void OnEndClose(IAsyncResult result)
{
ChainedAsyncResult.End(result);
}
public override T GetProperty<T>()
{
if (typeof(T) == typeof(TypedServiceChannelFactory<TChannel>))
{
return (T)(object)this;
}
T baseProperty = base.GetProperty<T>();
if (baseProperty != null)
{
return baseProperty;
}
return this.innerChannelFactory.GetProperty<T>();
}
}
class ServiceChannelFactoryOverOutput : TypedServiceChannelFactory<IOutputChannel>
{
public ServiceChannelFactoryOverOutput(IChannelFactory<IOutputChannel> innerChannelFactory, ClientRuntime clientRuntime, Binding binding)
: base(innerChannelFactory, clientRuntime, binding)
{
}
protected override IChannelBinder CreateInnerChannelBinder(EndpointAddress to, Uri via)
{
return new OutputChannelBinder(this.InnerChannelFactory.CreateChannel(to, via));
}
public override bool CanCreateChannel<TChannel>()
{
return (typeof(TChannel) == typeof(IOutputChannel)
|| typeof(TChannel) == typeof(IRequestChannel));
}
}
class ServiceChannelFactoryOverDuplex : TypedServiceChannelFactory<IDuplexChannel>
{
public ServiceChannelFactoryOverDuplex(IChannelFactory<IDuplexChannel> innerChannelFactory, ClientRuntime clientRuntime, Binding binding)
: base(innerChannelFactory, clientRuntime, binding)
{
}
protected override IChannelBinder CreateInnerChannelBinder(EndpointAddress to, Uri via)
{
return new DuplexChannelBinder(this.InnerChannelFactory.CreateChannel(to, via), this.RequestReplyCorrelator);
}
public override bool CanCreateChannel<TChannel>()
{
return (typeof(TChannel) == typeof(IOutputChannel)
|| typeof(TChannel) == typeof(IRequestChannel)
|| typeof(TChannel) == typeof(IDuplexChannel));
}
}
class ServiceChannelFactoryOverRequest : TypedServiceChannelFactory<IRequestChannel>
{
public ServiceChannelFactoryOverRequest(IChannelFactory<IRequestChannel> innerChannelFactory, ClientRuntime clientRuntime, Binding binding)
: base(innerChannelFactory, clientRuntime, binding)
{
}
protected override IChannelBinder CreateInnerChannelBinder(EndpointAddress to, Uri via)
{
return new RequestChannelBinder(this.InnerChannelFactory.CreateChannel(to, via));
}
public override bool CanCreateChannel<TChannel>()
{
return (typeof(TChannel) == typeof(IOutputChannel)
|| typeof(TChannel) == typeof(IRequestChannel));
}
}
class ServiceChannelFactoryOverOutputSession : TypedServiceChannelFactory<IOutputSessionChannel>
{
bool datagramAdapter;
public ServiceChannelFactoryOverOutputSession(IChannelFactory<IOutputSessionChannel> innerChannelFactory, ClientRuntime clientRuntime, Binding binding, bool datagramAdapter)
: base(innerChannelFactory, clientRuntime, binding)
{
this.datagramAdapter = datagramAdapter;
}
protected override IChannelBinder CreateInnerChannelBinder(EndpointAddress to, Uri via)
{
IOutputChannel channel;
if (this.datagramAdapter)
{
channel = DatagramAdapter.GetOutputChannel(
delegate() { return this.InnerChannelFactory.CreateChannel(to, via); },
timeouts);
}
else
{
channel = this.InnerChannelFactory.CreateChannel(to, via);
}
return new OutputChannelBinder(channel);
}
public override bool CanCreateChannel<TChannel>()
{
return (typeof(TChannel) == typeof(IOutputChannel)
|| typeof(TChannel) == typeof(IOutputSessionChannel)
|| typeof(TChannel) == typeof(IRequestChannel)
|| typeof(TChannel) == typeof(IRequestSessionChannel));
}
}
class ServiceChannelFactoryOverDuplexSession : TypedServiceChannelFactory<IDuplexSessionChannel>
{
bool useActiveAutoClose;
public ServiceChannelFactoryOverDuplexSession(IChannelFactory<IDuplexSessionChannel> innerChannelFactory, ClientRuntime clientRuntime, Binding binding, bool useActiveAutoClose)
: base(innerChannelFactory, clientRuntime, binding)
{
this.useActiveAutoClose = useActiveAutoClose;
}
protected override IChannelBinder CreateInnerChannelBinder(EndpointAddress to, Uri via)
{
return new DuplexChannelBinder(this.InnerChannelFactory.CreateChannel(to, via), this.RequestReplyCorrelator, useActiveAutoClose);
}
public override bool CanCreateChannel<TChannel>()
{
return (typeof(TChannel) == typeof(IOutputChannel)
|| typeof(TChannel) == typeof(IRequestChannel)
|| typeof(TChannel) == typeof(IDuplexChannel)
|| typeof(TChannel) == typeof(IOutputSessionChannel)
|| typeof(TChannel) == typeof(IRequestSessionChannel)
|| typeof(TChannel) == typeof(IDuplexSessionChannel));
}
}
class ServiceChannelFactoryOverRequestSession : TypedServiceChannelFactory<IRequestSessionChannel>
{
bool datagramAdapter = false;
public ServiceChannelFactoryOverRequestSession(IChannelFactory<IRequestSessionChannel> innerChannelFactory, ClientRuntime clientRuntime, Binding binding, bool datagramAdapter)
: base(innerChannelFactory, clientRuntime, binding)
{
this.datagramAdapter = datagramAdapter;
}
protected override IChannelBinder CreateInnerChannelBinder(EndpointAddress to, Uri via)
{
IRequestChannel channel;
if (this.datagramAdapter)
{
channel = DatagramAdapter.GetRequestChannel(
delegate() { return this.InnerChannelFactory.CreateChannel(to, via); },
this.timeouts);
}
else
{
channel = this.InnerChannelFactory.CreateChannel(to, via);
}
return new RequestChannelBinder(channel);
}
public override bool CanCreateChannel<TChannel>()
{
return (typeof(TChannel) == typeof(IOutputChannel)
|| typeof(TChannel) == typeof(IOutputSessionChannel)
|| typeof(TChannel) == typeof(IRequestChannel)
|| typeof(TChannel) == typeof(IRequestSessionChannel));
}
}
class DefaultCommunicationTimeouts : IDefaultCommunicationTimeouts
{
TimeSpan closeTimeout;
TimeSpan openTimeout;
TimeSpan receiveTimeout;
TimeSpan sendTimeout;
public DefaultCommunicationTimeouts(IDefaultCommunicationTimeouts timeouts)
{
this.closeTimeout = timeouts.CloseTimeout;
this.openTimeout = timeouts.OpenTimeout;
this.receiveTimeout = timeouts.ReceiveTimeout;
this.sendTimeout = timeouts.SendTimeout;
}
public TimeSpan CloseTimeout
{
get { return this.closeTimeout; }
}
public TimeSpan OpenTimeout
{
get { return this.openTimeout; }
}
public TimeSpan ReceiveTimeout
{
get { return this.receiveTimeout; }
}
public TimeSpan SendTimeout
{
get { return this.sendTimeout; }
}
}
}
}
|