private static void Main(string[] args)
        {
            // The client and server must agree on the interface id to use:
            var iid = new Guid("{1B617C4B-BF68-4B8C-AE2B-A77E6A3ECEC5}");

            bool attempt = true;
            while (attempt)
            {
                attempt = false;
                // Open the connection based on the endpoint information and interface IID
                using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "RpcExampleClientServer"))
                    //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
                {
                    // Provide authentication information (not nessessary for LRPC)
                    client.AuthenticateAs(RpcClientApi.Self);

                    // Send the request and get a response
                    try
                    {
                        var response = client.Execute(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetings" : args[0]));
                        Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));
                    }
                    catch (RpcException rx)
                    {
                        if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
                        {
                            //Use a wait handle if your on the same box...
                            Console.Error.WriteLine("Waiting for server...");
                            System.Threading.Thread.Sleep(1000);
                            attempt = true;
                        }
                        else
                            Console.Error.WriteLine(rx);
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                    }
                }
            }
            // done...
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
Beispiel #2
0
        public override void Initialize(IEventSource eventSource)
        {
            if (eventSource == null) {
                return;
            }

            var p = Parameters.Split(';');

            if (p.Length < 2) {
                throw new Exception("Requires at least pipeName and guid");
            }

            var pipeName = p[0];
            var iid = new Guid(p[1]);

            _client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, pipeName);
            messagePump = Task.Factory.StartNew(() => {
                try {
                    BuildMessage msg;

                    while (!stop || _messages.Count > 0) {
                        if (_messages.TryDequeue(out msg)) {
                            var result = _client.Execute(msg.ToByteArray());
                            if (result.Length > 0 && result[1] == 0x01) {
                                // we've been asked to kill ourselves.
                                stop = true;
                            }
                            continue;
                        }
                        Thread.Sleep(5);
                    }
                }
                finally {
                    stop = true;
                }

            });

            eventSource.BuildFinished += eventSource_BuildFinished;
            eventSource.BuildStarted += eventSource_BuildStarted;
            eventSource.CustomEventRaised += eventSource_CustomEventRaised;
            eventSource.ErrorRaised += eventSource_ErrorRaised;
            eventSource.MessageRaised += eventSource_MessageRaised;
            eventSource.ProjectFinished += eventSource_ProjectFinished;
            eventSource.ProjectStarted += eventSource_ProjectStarted;
            //eventSource.StatusEventRaised += eventSource_StatusEventRaised;
            eventSource.TargetFinished += eventSource_TargetFinished;
            eventSource.TargetStarted += eventSource_TargetStarted;
            eventSource.TaskFinished += eventSource_TaskFinished;
            eventSource.TaskStarted += eventSource_TaskStarted;
            eventSource.WarningRaised += eventSource_WarningRaised;
        }
Beispiel #3
0
        public void Dispose()
        {
            stop = true;
            if (messagePump != null) {
                messagePump.Wait();
            }

            if (_client != null) {
                _client.Dispose();
                _client = null;
            }
        }
 public Win32RpcClient(Guid iid, string protocol, string server, string endpoint)
 {
     _client = new RpcClientApi(iid, Parse(protocol), server, endpoint);
 }