Пример #1
0
 protected virtual void Close()
 {
     try
     {
         if (_callContext.HasSessionId)
         {
             CallMethod(".close", RpcVoid.DefaultInstance, RpcVoid.CreateBuilder());
             _callContext.ClearSessionId();
         }
     }
     catch (Exception e)
     {
         Trace.TraceWarning("Exception on close connection: {0}", e);
     }
 }
Пример #2
0
        public void ClientInformationTest()
        {
            //Create the server with a stub pointing to our implementation
            using (Win32RpcServer server = RpcServer.CreateRpc(iid, new ClientInformationFilter())
                                           .AddAuthWinNT()
                                           .AddProtocol("ncalrpc", "lrpctest")
                                           .AddProtocol("ncacn_ip_tcp", "12345")
                                           .AddProtocol("ncacn_np", @"\pipe\p1"))
            {
                server.StartListening();

                using (
                    RpcClient client =
                        RpcClient.ConnectRpc(iid, "ncalrpc", null, "lrpctest").Authenticate(RpcAuthenticationType.Self))
                    client.CallMethod("ncalrpc", RpcVoid.DefaultInstance, RpcVoid.CreateBuilder());

                using (
                    RpcClient client =
                        RpcClient.ConnectRpc(iid, "ncacn_ip_tcp", "127.0.0.1", "12345").Authenticate(
                            RpcAuthenticationType.Self))
                    client.CallMethod("ncacn_ip_tcp", RpcVoid.DefaultInstance, RpcVoid.CreateBuilder());

                using (
                    RpcClient client =
                        RpcClient.ConnectRpc(iid, "ncacn_np", @"\\localhost", @"\pipe\p1").Authenticate(
                            RpcAuthenticationType.Anonymous))
                    client.CallMethod("ncacn_np-Anonymous", RpcVoid.DefaultInstance, RpcVoid.CreateBuilder());

                server.AddAuthNegotiate(); //winnt authentication not supported over pipes... need to allow nego
                using (
                    RpcClient client =
                        RpcClient.ConnectRpc(iid, "ncacn_np", @"\\localhost", @"\pipe\p1").Authenticate(
                            RpcAuthenticationType.Self))
                    client.CallMethod("ncacn_np", RpcVoid.DefaultInstance, RpcVoid.CreateBuilder());
            }
        }
Пример #3
0
        TMessage IRpcDispatch.CallMethod <TMessage, TBuilder>(string method, IMessageLite request,
                                                              IBuilderLite <TMessage, TBuilder> response)
        {
            int size = request.SerializedSize;

            if (size < multiPartThreshold)
            {
                return(next.CallMethod(method, request, response));
            }
            else
            {
                ByteString transaction  = ByteString.CopyFrom(Guid.NewGuid().ToByteArray());
                byte[]     requestBytes = request.ToByteArray();

                RpcMultiPartRequest.Types.RpcMessageStatus status = RpcMultiPartRequest.Types.RpcMessageStatus.CONTINUE;
                try
                {
                    int total = requestBytes.Length;
                    int amt   = multiPartThreshold - 1024; //reserved for header
                    RpcMultiPartResponse mpr = RpcMultiPartResponse.DefaultInstance;

                    for (int pos = 0; pos < total; pos += amt)
                    {
                        amt    = Math.Min(amt, total - pos);
                        status = (pos + amt) < total ? status : RpcMultiPartRequest.Types.RpcMessageStatus.COMPLETE;
                        mpr    = next.CallMethod(".multi",
                                                 RpcMultiPartRequest.CreateBuilder()
                                                 .SetTransactionId(transaction)
                                                 .SetMethodName(method)
                                                 .SetMessageStatus(status)
                                                 .SetCurrentPosition(pos)
                                                 .SetTotalBytes(total)
                                                 .SetBytesSent(amt)
                                                 .SetPayloadBytes(ByteString.CopyFrom(requestBytes, pos, amt))
                                                 .Build(),
                                                 RpcMultiPartResponse.CreateBuilder()
                                                 );
                        if (!mpr.Continue)
                        {
                            throw new InvalidDataException("The operation was canceled by the server.");
                        }
                    }
                    if (!mpr.HasResponseBytes)
                    {
                        throw new InvalidDataException("The server did not provide a response.");
                    }

                    return(response.MergeFrom(mpr.ResponseBytes.ToByteArray(), extensions).Build());
                }
                catch
                {
                    if (status == RpcMultiPartRequest.Types.RpcMessageStatus.CONTINUE)
                    {
                        try
                        {
                            next.CallMethod(".multi",
                                            RpcMultiPartRequest.CreateBuilder()
                                            .SetTransactionId(transaction)
                                            .SetMessageStatus(RpcMultiPartRequest.Types.RpcMessageStatus.CANCEL)
                                            .Build(),
                                            RpcVoid.CreateBuilder()
                                            );
                        }
                        catch (Exception e)
                        {
                            Trace.TraceWarning("Unable to cancel multi-part message: {0}, error = {1}", transaction, e);
                        }
                    }
                    throw;
                }
            }
        }