Skip to content

Commit

Permalink
2009-08-20 Atsushi Enomoto <atsushi@ximian.com>
Browse files Browse the repository at this point in the history
	* DuplexChannelFactory.cs, ChannelFactory_1.cs: with static factory
	  methods, they should close the factory when the channel is closed,
	  but nonstatic CreateChannel() could be called more than once, so
	  do not always close it.
	* ClientRuntimeChannel.cs : take OperationContext.Current into
	  consideration (it could be created by users).


svn path=/trunk/mcs/; revision=140316
  • Loading branch information
atsushieno committed Aug 20, 2009
1 parent a190897 commit 70fb8c6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
9 changes: 9 additions & 0 deletions mcs/class/System.ServiceModel/System.ServiceModel/ChangeLog
@@ -1,3 +1,12 @@
2009-08-20 Atsushi Enomoto <atsushi@ximian.com>

* DuplexChannelFactory.cs, ChannelFactory_1.cs: with static factory
methods, they should close the factory when the channel is closed,
but nonstatic CreateChannel() could be called more than once, so
do not always close it.
* ClientRuntimeChannel.cs : take OperationContext.Current into
consideration (it could be created by users).

2009-08-19 Atsushi Enomoto <atsushi@ximian.com>

* NetNamedPipeBinding.cs, NetNamedPipeSecurity.cs
Expand Down
Expand Up @@ -111,14 +111,21 @@ public TChannel CreateChannel (EndpointAddress address)
return CreateChannel (address, null);
}

static TChannel CreateChannelCore (ChannelFactory<TChannel> cf, Func<ChannelFactory<TChannel>, TChannel> f)
{
var ch = f (cf);
((CommunicationObject) (object) ch).Closed += delegate { cf.Close (); };
return ch;
}

public static TChannel CreateChannel (Binding binding, EndpointAddress address)
{
return new ChannelFactory<TChannel> (binding, address).CreateChannel ();
return CreateChannelCore (new ChannelFactory<TChannel> (binding, address), f => f.CreateChannel ());
}

public static TChannel CreateChannel (Binding binding, EndpointAddress address, Uri via)
{
return new ChannelFactory<TChannel> (binding).CreateChannel (address, via);
return CreateChannelCore (new ChannelFactory<TChannel> (binding), f => f.CreateChannel (address, via));
}

public virtual TChannel CreateChannel (EndpointAddress address, Uri via)
Expand All @@ -135,7 +142,7 @@ public virtual TChannel CreateChannel (EndpointAddress address, Uri via)

protected static TChannel CreateChannel (string endpointConfigurationName)
{
return new ChannelFactory<TChannel> (endpointConfigurationName).CreateChannel ();
return CreateChannelCore (new ChannelFactory<TChannel> (endpointConfigurationName), f => f.CreateChannel ());
}

protected override ServiceEndpoint CreateDescription ()
Expand Down
Expand Up @@ -359,7 +359,7 @@ public void Dispose ()
protected override void OnAbort ()
{
channel.Abort ();
if (factory != null)
if (factory != null) // ... is it valid?
factory.Abort ();
}

Expand All @@ -382,8 +382,6 @@ protected override void OnClose (TimeSpan timeout)
{
DateTime start = DateTime.Now;
channel.Close (timeout);
if (factory != null)
factory.Close (timeout - (DateTime.Now - start));
}

protected override IAsyncResult OnBeginOpen (
Expand Down Expand Up @@ -574,6 +572,17 @@ Message CreateRequest (ClientOperation op, object [] parameters)
else
msg = (Message) parameters [0];

if (OperationContext.Current != null) {
// CopyHeadersFrom does not work here (brings duplicates -> error)
foreach (var mh in OperationContext.Current.OutgoingMessageHeaders) {
int x = msg.Headers.FindHeader (mh.Name, mh.Namespace, mh.Actor);
if (x >= 0)
msg.Headers.RemoveAt (x);
msg.Headers.Add ((MessageHeader) mh);
}
msg.Properties.CopyProperties (OperationContext.Current.OutgoingMessageProperties);
}

if (OutputSession != null)
msg.Headers.MessageId = new UniqueId (OutputSession.Id);
msg.Properties.AllowOutputBatching = AllowOutputBatching;
Expand Down
Expand Up @@ -223,6 +223,13 @@ public virtual TChannel CreateChannel (InstanceContext callbackInstance, Endpoin

// CreateChannel() factory methods

static TChannel CreateChannelCore (DuplexChannelFactory<TChannel> cf, Func<DuplexChannelFactory<TChannel>,TChannel> f)
{
var ch = f (cf);
((CommunicationObject) (object) ch).Closed += delegate { cf.Close (); };
return ch;
}

public static TChannel CreateChannel (object callbackObject, string endpointConfigurationName)
{
return CreateChannel (new InstanceContext (callbackObject), endpointConfigurationName);
Expand Down

0 comments on commit 70fb8c6

Please sign in to comment.