summaryrefslogtreecommitdiff
path: root/cs/demo/WCF/latency_m/Server.cs
blob: 8baef234fa78484f605ce50288906412131dc54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// **********************************************************************
//
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

using System;
using System.ServiceModel;
using System.Threading;

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,
                 InstanceContextMode = InstanceContextMode.Single)]
class LatencyI : Service.Latency
{
    public virtual void o()
    {
    }

    public virtual void shutdown()
    {
        Monitor.Enter(_sync);
        Monitor.Pulse(_sync);
        Monitor.Exit(_sync);
    }

    public static Object _sync;
};

class Server
{
    public static int Main(string[] args)
    {
        System.Console.WriteLine("starting up");
        string addr = null;
        string tcpPort = "10001";
        string httpPort = "10002";

        if(args.Length == 0)
        {
            addr = "127.0.0.1";
        }
        else if(args.Length == 1)
        {
            addr = args[0];
        }
        else if(args.Length == 3)
        {
            addr = args[0];
            tcpPort = args[1];
            httpPort = args[2];
        }
        else
        {
            Console.Error.WriteLine("usage: server [host [tcpPort httpPort]]");
            Environment.Exit(1);
        }

        try
        {
            ServiceHost host = new ServiceHost(typeof(LatencyI));
            LatencyI._sync = host;

            Uri uri = new Uri("net.tcp://" + addr + ":" + tcpPort);
            NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None);
            host.AddServiceEndpoint(typeof(Service.Latency), tcpBinding, uri);

            uri = new Uri("http://" + addr + ":" + httpPort);
            WSHttpBinding httpBinding = new WSHttpBinding(SecurityMode.None);
            host.AddServiceEndpoint(typeof(Service.Latency), httpBinding, uri);

            Monitor.Enter(host);
            host.Open();
            Monitor.Wait(host);
            Monitor.Exit(host);
            host.Close();
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine(ex);
            Environment.Exit(1);
        }
        return 0;
    }
}