sinks and sink chains
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsinkssinkchains.asp
using callcontext
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingcallcontext.asp
code modified from the sample by ingo rammer, author of “advanced .net remoting”:
using system;
using system.collections;
using system.io;
using system.runtime.remoting;
using system.runtime.remoting.messaging ;
using system.runtime.remoting.channels;
using system.threading;
using system.net;
namespace classlibremotingipsink
{
public class clientipserversinkprovider: iserverchannelsinkprovider
{
private iserverchannelsinkprovider next = null;
public clientipserversinkprovider(idictionary properties, icollection providerdata)
{
}
public void getchanneldata (ichanneldatastore channeldata)
{
}
public iserverchannelsink createsink (ichannelreceiver channel)
{
iserverchannelsink nextsink = null;
if (next != null)
{
nextsink = next.createsink(channel);
}
return new clientipserversink(nextsink);
}
public iserverchannelsinkprovider next
{
get { return next; }
set { next = value; }
}
}
public class clientipserversink : basechannelobjectwithproperties, iserverchannelsink, ichannelsinkbase
{
private iserverchannelsink _next;
public clientipserversink (iserverchannelsink next)
{
_next = next;
}
public void asyncprocessresponse ( system.runtime.remoting.channels.iserverresponsechannelsinkstack sinkstack , system.object state , system.runtime.remoting.messaging.imessage msg , system.runtime.remoting.channels.itransportheaders headers , system.io.stream stream )
{
}
public stream getresponsestream ( system.runtime.remoting.channels.iserverresponsechannelsinkstack sinkstack , system.object state , system.runtime.remoting.messaging.imessage msg , system.runtime.remoting.channels.itransportheaders headers )
{
return null;
}
public system.runtime.remoting.channels.serverprocessing processmessage(system.runtime.remoting.channels.iserverchannelsinkstack sinkstack, system.runtime.remoting.messaging.imessage requestmsg, system.runtime.remoting.channels.itransportheaders requestheaders, system.io.stream requeststream, out system.runtime.remoting.messaging.imessage responsemsg, out system.runtime.remoting.channels.itransportheaders responseheaders, out system.io.stream responsestream)
{
if (_next != null)
{
ipaddress ip = requestheaders[commontransportkeys.ipaddress] as ipaddress;
console.writeline(ip.tostring());
callcontext.setdata("clientipaddress",ip);
serverprocessing spres = _next.processmessage (sinkstack,requestmsg, requestheaders,requeststream,out responsemsg,out responseheaders,out responsestream);
return spres;
}
else
{
responsemsg=null;
responseheaders=null;
responsestream=null;
return new serverprocessing();
}
}
public iserverchannelsink nextchannelsink
{
get {return _next;}
set {_next = value;}
}
}
}
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




