config file vs code
- From: "blam" <bendlam@xxxxxxxxx>
- Date: 1 Mar 2007 06:53:39 -0800
I am trying to remote some objects using .net remoting. I
programmatically create the remote object on the client side with the
following code
bool found = false;
for (int i = 0; i <
ChannelServices.RegisteredChannels.Length; i++)
{
if
(ChannelServices.RegisteredChannels[i].ChannelName.Equals("tcp"))
{
found = true;
break;
}
}
if (!found)
{
BinaryClientFormatterSinkProvider clientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider =
new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 0;
props["typeFilterLevel"] =
TypeFilterLevel.Full;
TcpChannel chan = new TcpChannel(props,
clientProvider, serverProvider);
ChannelServices.RegisterChannel(chan, false);
}
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.AppendFormat("tcp://{0}:{1}/{2}/{3}",
remotingConfig.RemotingServerName, remotingConfig.RemotingPortNumber,
REMOTING_SERVICE_NAME, controllerType.Name);
Type typeofRI = controllerType;
object controllerExecRemoteObject =
Activator.GetObject(typeofRI,
sb.ToString());
controllerExecRemoteObject.GetType().GetMethod("Ping").Invoke(controllerExecRemoteObject,
null);
return controllerExecRemoteObject;
This works but randomly I get a socket exception "Exception has been
thrown by the target of an invocation." InnerException Message: No
connection could be made because the target machine actively refused
it
What is strange is when I run it using a config file to controll the
remoting like so, it works? Is there something missing in my code
above that the config file does that my code doesn't?
Here is the config:
<configuration>
<system.runtime.remoting>
<application name="et.Exec.ExecBase">
<client>
<wellknown type="et.Exec.Controllers.AlertControllerExec,
et.Exec.Controllers"
url="tcp://localhost:8057/etRemotingService/AlertControllerExec" /
</client>
<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
.
- Prev by Date: Re: Help on proper method ????
- Next by Date: Re: Help on proper method ????
- Previous by thread: Re: Help on proper method ????
- Next by thread: Re: i want to access remote desktop in dotnet
- Index(es):
Relevant Pages
|