Skip to content

Commit 162b0c2

Browse files
committed
Added some new options to the example service.
1 parent 3479f5e commit 162b0c2

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

ExampleRemotingService/Program.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,27 @@ static void Main(string[] args)
3636
{
3737
try
3838
{
39-
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
4039
bool secure = false;
41-
int port = 12345;
40+
int port = 12345;
4241
string ipc = String.Empty;
4342
bool showhelp = false;
4443
TypeFilterLevel typefilter = TypeFilterLevel.Low;
44+
CustomErrorsModes custom_errors = CustomErrorsModes.Off;
45+
string name = "RemotingServer";
4546

46-
OptionSet p = new OptionSet () {
47-
{ "s|secure", "Enable secure mode", v => secure = v != null },
48-
{ "p|port=", "Specify the local TCP port to listen on", v => port = int.Parse(v) },
49-
{ "t|typefilter=", "Specify the type filter level (low,full), default low",
50-
v => typefilter = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), v, true) },
51-
{ "i|ipc=", "Specify listening pipe name for IPC channel", v => ipc = v },
52-
{ "h|?|help", v => showhelp = v != null },
47+
OptionSet p = new OptionSet() {
48+
{ "s|secure", "Enable secure mode", v => secure = v != null },
49+
{ "p|port=", "Specify the local TCP port to listen on", v => port = int.Parse(v) },
50+
{ "t|typefilter=", "Specify the type filter level (low,full), default low",
51+
v => typefilter = (TypeFilterLevel)Enum.Parse(typeof(TypeFilterLevel), v, true) },
52+
{ "i|ipc=", "Specify listening pipe name for IPC channel", v => ipc = v },
53+
{ "e|error=", "Set custom error mode (On, Off, RemoteOnly) (don't show full errors in remote calls)",
54+
v => custom_errors = (CustomErrorsModes)Enum.Parse(typeof(CustomErrorsModes), v, true) },
55+
{ "n|name=", "Set the remoting class name", v => name = v },
56+
{ "h|?|help", v => showhelp = v != null },
5357
};
54-
55-
p.Parse (args);
58+
59+
p.Parse(args);
5660

5761
if (showhelp)
5862
{
@@ -62,6 +66,8 @@ static void Main(string[] args)
6266
}
6367
else
6468
{
69+
RemotingConfiguration.CustomErrorsMode = custom_errors;
70+
6571
Trace.Listeners.Add(new ConsoleTraceListener(true));
6672

6773
IChannel chan;
@@ -70,7 +76,7 @@ static void Main(string[] args)
7076
BinaryServerFormatterSinkProvider serverSinkProvider = new BinaryServerFormatterSinkProvider();
7177
serverSinkProvider.TypeFilterLevel = typefilter;
7278

73-
if (!String.IsNullOrEmpty(ipc))
79+
if (!string.IsNullOrEmpty(ipc))
7480
{
7581
properties["portName"] = ipc;
7682
properties["authorizedGroup"] = "Everyone";
@@ -87,13 +93,12 @@ static void Main(string[] args)
8793

8894
RemotingConfiguration.RegisterWellKnownServiceType(
8995
typeof(RemoteType),
90-
"RemotingServer",
96+
name,
9197
WellKnownObjectMode.Singleton);
9298

9399
bool isipc = chan is IpcChannel;
94100

95-
Console.WriteLine("Server Activated at {0}://{1}/RemotingServer", isipc ? "ipc" : "tcp", isipc ? ipc : "HOST:" + port.ToString());
96-
101+
Console.WriteLine("Server Activated at {0}://{1}/{2}", isipc ? "ipc" : "tcp", isipc ? ipc : "HOST:" + port.ToString(), name);
97102
Console.ReadLine();
98103
}
99104
}

0 commit comments

Comments
 (0)