Exemplo n.º 1
0
        // MessageToProtocolRequest
        //
        // Converts a IMessage representing a method call (IMethodCallMessage)
        // into the Ice protocol representation, and writes it to stream outStream.
        public static void MessageToProtocolRequest(Stream outStream, IMessage msg)
        {
            IMethodCallMessage mcall = msg as IMethodCallMessage;

            Ice.ProtocolWriter pw = new Ice.ProtocolWriter(outStream);

            // extract message bits from mcall
            Ice.Identity      id        = (Ice.Identity)mcall.LogicalCallContext.GetData("__iceIdentity");
            string[]          facetPath = (string[])mcall.LogicalCallContext.GetData("__iceFacetPath");
            Ice.OperationMode opMode    = (Ice.OperationMode)mcall.LogicalCallContext.GetData("__iceOperationMode");
            Ice.Context       ctx       = (Ice.Context)mcall.LogicalCallContext.GetData("__iceContext");
            bool oneWay = (bool)mcall.LogicalCallContext.GetData("__iceOneWay");


            int thisRequestId = 0;

            if (!oneWay)
            {
                thisRequestId = IceChannelUtils.NextRequestId;
            }

            mcall.LogicalCallContext.SetData("__iceRequestId", thisRequestId);

            ParameterInfo[] paramInfos = mcall.MethodBase.GetParameters();

            // Create an Ice protocol message
            pw.BeginMessage(Ice.MessageType.Request);
            pw.WriteRequestMessageHeader(thisRequestId,
                                         id,
                                         facetPath,
                                         mcall.MethodName,
                                         Ice.OperationMode.Normal,
                                         ctx);

            // now write the args
            pw.BeginEncapsulation();
            for (int i = 0; i < mcall.ArgCount; i++)
            {
                if (!paramInfos[i].IsOut)
                {
                    if (Attribute.GetCustomAttribute(paramInfos[i], typeof(Ice.AsProxy)) != null)
                    {
                        pw.WriteProxy(mcall.Args[i], paramInfos[i].ParameterType);
                    }
                    else
                    {
                        pw.WriteObject(mcall.Args[i], paramInfos[i].ParameterType);
                    }
                }
            }
            pw.WriteClassInstances();
            pw.EndEncapsulation();
            pw.EndMessage();
        }
Exemplo n.º 2
0
    // MessageToProtocolRequest
    //
    // Converts a IMessage representing a method call (IMethodCallMessage)
    // into the Ice protocol representation, and writes it to stream outStream.
    public static void MessageToProtocolRequest (Stream outStream, IMessage msg)
    {
      IMethodCallMessage mcall = msg as IMethodCallMessage;
      Ice.ProtocolWriter pw = new Ice.ProtocolWriter(outStream);

      // extract message bits from mcall
      Ice.Identity id = (Ice.Identity) mcall.LogicalCallContext.GetData("__iceIdentity");
      string[] facetPath = (string[]) mcall.LogicalCallContext.GetData("__iceFacetPath");
      Ice.OperationMode opMode = (Ice.OperationMode) mcall.LogicalCallContext.GetData("__iceOperationMode");
      Ice.Context ctx = (Ice.Context) mcall.LogicalCallContext.GetData("__iceContext");
      bool oneWay = (bool) mcall.LogicalCallContext.GetData("__iceOneWay");


      int thisRequestId = 0;
      if (!oneWay)
        thisRequestId = IceChannelUtils.NextRequestId;

      mcall.LogicalCallContext.SetData("__iceRequestId", thisRequestId);

      ParameterInfo[] paramInfos = mcall.MethodBase.GetParameters();

      // Create an Ice protocol message
      pw.BeginMessage (Ice.MessageType.Request);
      pw.WriteRequestMessageHeader (thisRequestId,
                                    id,
                                    facetPath,
                                    mcall.MethodName,
                                    Ice.OperationMode.Normal,
                                    ctx);

      // now write the args
      pw.BeginEncapsulation();
      for (int i = 0; i < mcall.ArgCount; i++) {
        if (!paramInfos[i].IsOut) {
          if (Attribute.GetCustomAttribute (paramInfos[i], typeof(Ice.AsProxy)) != null)
            pw.WriteProxy (mcall.Args[i], paramInfos[i].ParameterType);
          else
            pw.WriteObject (mcall.Args[i], paramInfos[i].ParameterType);
        }
      }
      pw.WriteClassInstances();
      pw.EndEncapsulation();
      pw.EndMessage();
    }
Exemplo n.º 3
0
        // MessageToProtocolReply
        //
        // Given a IMethodReturnMessage replyMsg, which originated from the
        // original IMethodMessage callMsg, serialize the reply using the
        // Ice protocol to outStream
        public static void MessageToProtocolReply(IMessage callMsg, IMessage replyMsg, Stream outStream)
        {
            IMethodMessage       cmsg   = callMsg as IMethodMessage;
            IMethodReturnMessage retmsg = replyMsg as IMethodReturnMessage;

            if (cmsg == null || retmsg == null)
            {
                throw new InvalidOperationException("no IMethodReturnMessage????");
            }

            if (retmsg.Exception != null)
            {
                Trace.WriteLine("retmsg.Exception != null, don't know what to do");
                Console.WriteLine(retmsg.Exception);
                return;
            }

            int requestId = (int)callMsg.Properties["__iceRequestId"];

            Ice.ProtocolWriter pw = new Ice.ProtocolWriter(outStream);
            pw.BeginMessage(Ice.MessageType.Reply);
            pw.WriteReplyMessageHeader(MessageReplyType.Success,
                                       requestId);

            pw.BeginEncapsulation();
            // first write the out params
            object[] outArgs   = retmsg.OutArgs;
            int      curOutArg = 0;

            MethodInfo mi = cmsg.MethodBase as MethodInfo;

            ParameterInfo[] paramInfos = mi.GetParameters();
            foreach (ParameterInfo pinfo in paramInfos)
            {
                if (pinfo.IsOut)
                {
                    if (Attribute.GetCustomAttribute(pinfo, typeof(Ice.AsProxy)) != null)
                    {
                        pw.WriteProxy(outArgs[curOutArg++], pinfo.ParameterType);
                    }
                    else
                    {
                        pw.WriteObject(outArgs[curOutArg++], pinfo.ParameterType);
                    }
                }
            }

            Type rtype = mi.ReturnType;

            if (rtype != null && rtype != typeof(void))
            {
                if (mi.ReturnTypeCustomAttributes.IsDefined(typeof(Ice.AsProxy), true))
                {
                    pw.WriteProxy(retmsg.ReturnValue, rtype);
                }
                else
                {
                    pw.WriteObject(retmsg.ReturnValue, rtype);
                }
            }
            pw.WriteClassInstances();
            pw.EndEncapsulation();
            pw.EndMessage();
        }
Exemplo n.º 4
0
    // MessageToProtocolReply
    //
    // Given a IMethodReturnMessage replyMsg, which originated from the
    // original IMethodMessage callMsg, serialize the reply using the
    // Ice protocol to outStream
    public static void MessageToProtocolReply (IMessage callMsg, IMessage replyMsg, Stream outStream)
    {
      IMethodMessage cmsg = callMsg as IMethodMessage;
      IMethodReturnMessage retmsg = replyMsg as IMethodReturnMessage;

      if (cmsg == null || retmsg == null)
        throw new InvalidOperationException ("no IMethodReturnMessage????");

      if (retmsg.Exception != null) {
        Trace.WriteLine ("retmsg.Exception != null, don't know what to do");
        Console.WriteLine (retmsg.Exception);
        return;
      }

      int requestId = (int) callMsg.Properties["__iceRequestId"];

      Ice.ProtocolWriter pw = new Ice.ProtocolWriter (outStream);
      pw.BeginMessage (Ice.MessageType.Reply);
      pw.WriteReplyMessageHeader (MessageReplyType.Success,
                                  requestId);

      pw.BeginEncapsulation();
      // first write the out params
      object[] outArgs = retmsg.OutArgs;
      int curOutArg = 0;

      MethodInfo mi = cmsg.MethodBase as MethodInfo;
      ParameterInfo[] paramInfos = mi.GetParameters();
      foreach (ParameterInfo pinfo in paramInfos) {
        if (pinfo.IsOut) {
          if (Attribute.GetCustomAttribute (pinfo, typeof(Ice.AsProxy)) != null)
            pw.WriteProxy (outArgs[curOutArg++], pinfo.ParameterType);
          else
            pw.WriteObject (outArgs[curOutArg++], pinfo.ParameterType);
        }
      }

      Type rtype = mi.ReturnType;
      if (rtype != null && rtype != typeof(void)) {
        if (mi.ReturnTypeCustomAttributes.IsDefined (typeof(Ice.AsProxy), true))
          pw.WriteProxy (retmsg.ReturnValue, rtype);
        else
          pw.WriteObject (retmsg.ReturnValue, rtype);
      }
      pw.WriteClassInstances();
      pw.EndEncapsulation();
      pw.EndMessage ();
    }