NAT and Remoting
- From: "venkats_n" <venkats_n@xxxxxxxxxxx>
- Date: 21 Aug 2005 11:36:14 -0700
I am developing an WinForms based application used 90% within a LAN and
10% across the Internet though the Internet use may increase over time.
This application uses the remoting technology.
The application does not work for Natted IP addresses.
I tried to work around this problem with the reference of the post "nat
routing, firewalls and remoting" in the same forum.
I have reached someplace, but I am now struggling to proceed further.
The steps I followed :
1. Created a Server Side Sink and registered it through the web.config
as I am using IIS as host for my remote object
<system.runtime.remoting>
<application>
<channels>
<channel ref="http">
<serverProviders>
<provider type="SinkAssembly.ServerSinkProvider, SinkAssembly"/>
<formatter ref="soap" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
.....
2. The sink looks somewhat like this :
public class ServerSink : BaseChannelSinkWithProperties,
IServerChannelSink
{
private IServerChannelSink _nextSink;
public ServerSink(IServerChannelSink next)
{
_nextSink = next;
}
public IServerChannelSink NextChannelSink
{
get
{
return _nextSink;
}
}
.....
.....
public ServerProcessing ProcessMessage(IServerChannelSinkStack
sinkStack,
IMessage requestMsg,
ITransportHeaders requestHeaders,
Stream requestStream,
out IMessage responseMsg,
out ITransportHeaders responseHeaders,
out Stream responseStream)
{
IPAddress ipAddress =
requestHeaders[CommonTransportKeys.IPAddress] as IPAddress;
CallContext.SetData("ClientIP",ipAddress);
ServerProcessing srvProc = _nextSink.ProcessMessage(sinkStack,
requestMsg,
requestHeaders,
requestStream,
out responseMsg,
out responseHeaders,
out responseStream);
return ServerProcessing.Complete;
}
3. Created a Tracking Handler class.
public class TrackingHandler : ITrackingHandler
{
public void MarshaledObject(Object obj, ObjRef or)
{
....................
....................
IPAddress ipAddress = (IPAddress )CallContext.GetData("ClientIP");
object[] MyChannelData = new object[or.ChannelInfo.ChannelData.Length
];
for ( int i = or.ChannelInfo.ChannelData.GetLowerBound(0); i <=
or.ChannelInfo.ChannelData.GetUpperBound(0); i++ )
{
if(or.ChannelInfo.ChannelData[i] is ChannelDataStore)
{
//then manipulate the ChannelUris
}
}
..........................
4. Derieved all my Remote Object classes from a Base Class which looks
like this :
public abstract class RemotingBase : MarshalByRefObject
{
private static bool bProbingStarted = false;
private TrackingHandler trkHndlr = null;
..................
.........
....
...
..
public RemotingBase()
{
StartProbing ();
}
~RemotingBase()
{
StopProbing();
}
#region Methods for Tracking Handler
private void StartProbing ()
{
if (bProbingStarted != true)
{
StartRemoteServerTrackingHandler ();
bProbingStarted = true;
}
}
private void StopProbing ()
{
if (bProbingStarted == true)
{
StopRemoteServerTrackingHandler ();
bProbingStarted = false;
}
}
private void StartRemoteServerTrackingHandler ()
{
trkHndlr = new TrackingHandler();
TrackingServices.RegisterTrackingHandler (trkHndlr);
}
private void StopRemoteServerTrackingHandler()
{
if (null != trkHndlr)
{
TrackingServices.UnregisterTrackingHandler (trkHndlr);
}
}
................
}
Thanks and Regards,
Venkat
.
- Follow-Ups:
- Re: NAT and Remoting
- From: Venkatasubramanian Narasimhan
- Re: NAT and Remoting
- From: Henry Willsun
- Re: NAT and Remoting
- From: Allen Anderson
- Re: NAT and Remoting
- Prev by Date: The underlying connection was closed: An unexpected error occurred on a receive
- Next by Date: Re: Remoting events problem HELP !
- Previous by thread: The underlying connection was closed: An unexpected error occurred on a receive
- Next by thread: Re: NAT and Remoting
- Index(es):
Relevant Pages
|