Selaa lähdekoodia

2009-08-14 Atsushi Enomoto <[email protected]>

	* DuplexChannelBase.cs, TcpDuplexSessionChannel.cs :
	  get local and remote address of connected counterpart to get
	  callback channel connected.
	* PeerDuplexChannel.cs : remove FIXME wrt above.


svn path=/trunk/mcs/; revision=139903
Atsushi Eno 16 vuotta sitten
vanhempi
sitoutus
4db580beaf

+ 7 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,10 @@
+2009-08-14  Atsushi Enomoto  <[email protected]>
+
+	* DuplexChannelBase.cs, TcpDuplexSessionChannel.cs :
+	  get local and remote address of connected counterpart to get
+	  callback channel connected.
+	* PeerDuplexChannel.cs : remove FIXME wrt above.
+
 2009-08-07  Atsushi Enomoto  <[email protected]>
 
 	* PeerDuplexChannel.cs : add fixme comment and remove extra FIXME.

+ 2 - 2
mcs/class/System.ServiceModel/System.ServiceModel.Channels/DuplexChannelBase.cs

@@ -57,11 +57,11 @@ namespace System.ServiceModel.Channels
 			SetupDelegates ();
 		}
 
-		public EndpointAddress LocalAddress {
+		public virtual EndpointAddress LocalAddress {
 			get { return local_address; }
 		}
 
-		public EndpointAddress RemoteAddress {
+		public virtual EndpointAddress RemoteAddress {
 			get { return remote_address; }
 		}
 

+ 0 - 2
mcs/class/System.ServiceModel/System.ServiceModel.Channels/PeerDuplexChannel.cs

@@ -84,8 +84,6 @@ namespace System.ServiceModel.Channels
 					throw new ArgumentNullException ("connect");
 try {
 				var ch = OperationContext.Current.GetCallbackChannel<IPeerConnectorContract> ();
-// FIXME: so, this duplex channel, when created by a listener, lacks RemoteAddress to send callback. Get it from somewhere.
-Console.WriteLine ("FIXME FIXME:" + ((IContextChannel) ch).RemoteAddress);
 				// FIXME: check and reject if inappropriate.
 				ch.Welcome (new WelcomeInfo () { NodeId = connect.NodeId });
 

+ 18 - 1
mcs/class/System.ServiceModel/System.ServiceModel.Channels/TcpDuplexSessionChannel.cs

@@ -69,6 +69,7 @@ namespace System.ServiceModel.Channels
 		bool is_service_side;
 		TcpBinaryFrameManager frame;
 		TcpDuplexSession session; // do not use this directly. Use Session instead.
+		EndpointAddress counterpart_address;
 		
 		public TcpDuplexSessionChannel (ChannelFactoryBase factory, TcpChannelInfo info, EndpointAddress address, Uri via)
 			: base (factory, address, via)
@@ -79,6 +80,7 @@ namespace System.ServiceModel.Channels
 			// make sure to acquire TcpClient here.
 			int explicitPort = Via.Port;
 			client = new TcpClient (Via.Host, explicitPort <= 0 ? TcpTransportBindingElement.DefaultPort : explicitPort);
+			counterpart_address = GetEndpointAddressFromTcpClient (client);
 		}
 		
 		public TcpDuplexSessionChannel (ChannelListenerBase listener, TcpChannelInfo info, TcpClient client)
@@ -87,12 +89,27 @@ namespace System.ServiceModel.Channels
 			is_service_side = true;
 			this.client = client;
 			this.info = info;
+			counterpart_address = GetEndpointAddressFromTcpClient (client);
 		}
-		
+
+		EndpointAddress GetEndpointAddressFromTcpClient (TcpClient client)
+		{
+			IPEndPoint ep = (IPEndPoint) client.Client.RemoteEndPoint;
+			return new EndpointAddress (new Uri ("net.tcp://" + ep));
+		}
+
 		public MessageEncoder Encoder {
 			get { return info.MessageEncoder; }
 		}
 
+		public override EndpointAddress RemoteAddress {
+			get { return base.RemoteAddress ?? counterpart_address; }
+		}
+
+		public override EndpointAddress LocalAddress {
+			get { return base.LocalAddress ?? counterpart_address; }
+		}
+
 		public IDuplexSession Session {
 			get {
 				if (session == null)