Пример #1
0
 public AsyncInvokeContextBase(HproseClient client, string functionName, object[] arguments, HproseErrorEvent errorCallback, Type returnType, bool byRef, HproseResultMode resultMode, bool simple)
 {
     this.client        = client;
     this.functionName  = functionName;
     this.arguments     = arguments;
     this.errorCallback = (errorCallback == null) ? client.OnError : errorCallback;
     this.returnType    = returnType;
     this.byRef         = byRef;
     this.resultMode    = resultMode;
     this.simple        = simple;
     this.syncContext   = HproseClient.SynchronizationContext;
     this.context       = new HproseClientContext(client);
 }
Пример #2
0
        public object Invoke(string functionName, object[] arguments, Type returnType, bool byRef, HproseResultMode resultMode, bool simple)
        {
            HproseClientContext context = new HproseClientContext(this);
            object result = DoInput(SendAndReceive(
                                        DoOutput(functionName, arguments, byRef, simple, context)
                                        ), arguments, returnType, resultMode, context);

            if (result is HproseException)
            {
                throw (HproseException)result;
            }
            return(result);
        }
Пример #3
0
        private object DoInput(MemoryStream inData, object[] arguments, Type returnType, HproseResultMode resultMode, HproseClientContext context)
        {
            for (int i = filters.Count - 1; i >= 0; --i)
            {
                inData.Position = 0;
#if (dotNET10 || dotNET11 || dotNETCF10 || dotNETMF)
                IHproseFilter filter = (IHproseFilter)filters[i];
                inData = filter.InputFilter(inData, context);
#else
                inData = filters[i].InputFilter(inData, context);
#endif
            }
            inData.Position = inData.Length - 1;
            int tag = inData.ReadByte();
            if (tag != HproseTags.TagEnd)
            {
                throw new HproseException("Wrong Response: \r\n" + HproseHelper.ReadWrongInfo(inData));
            }
            inData.Position = 0;
            if (resultMode == HproseResultMode.Raw)
            {
                inData.SetLength(inData.Length - 1);
            }
            if (resultMode == HproseResultMode.RawWithEndTag ||
                resultMode == HproseResultMode.Raw)
            {
                return(MemoryStreamToType(inData, returnType));
            }
            object result = null;
#if !dotNETMF
            HproseReader reader = new HproseReader(inData, mode);
#else
            HproseReader reader = new HproseReader(inData);
#endif
            while ((tag = inData.ReadByte()) != HproseTags.TagEnd)
            {
                switch (tag)
                {
                case HproseTags.TagResult:
                    if (resultMode == HproseResultMode.Normal)
                    {
                        reader.Reset();
                        result = reader.Unserialize(returnType);
                    }
                    else
                    {
                        result = MemoryStreamToType(reader.ReadRaw(), returnType);
                    }
                    break;

                case HproseTags.TagArgument:
                    reader.Reset();
                    Object[] args   = reader.ReadObjectArray();
                    int      length = arguments.Length;
                    if (length > args.Length)
                    {
                        length = args.Length;
                    }
                    Array.Copy(args, 0, arguments, 0, length);
                    break;

                case HproseTags.TagError:
                    reader.Reset();
                    result = new HproseException(reader.ReadString());
                    break;

                default:
                    throw new HproseException("Wrong Response: \r\n" + HproseHelper.ReadWrongInfo(inData));
                }
            }
            return(result);
        }
Пример #4
0
        private MemoryStream DoOutput(string functionName, object[] arguments, bool byRef, bool simple, HproseClientContext context)
        {
            MemoryStream outData = new MemoryStream();

#if !dotNETMF
            HproseWriter writer = new HproseWriter(outData, mode, simple);
#else
            HproseWriter writer = new HproseWriter(outData, simple);
#endif
            outData.WriteByte(HproseTags.TagCall);
            writer.WriteString(functionName);
            if ((arguments != null) && (arguments.Length > 0 || byRef))
            {
                writer.Reset();
                writer.WriteArray(arguments);
                if (byRef)
                {
                    writer.WriteBoolean(true);
                }
            }
            outData.WriteByte(HproseTags.TagEnd);
            outData.Position = 0;
            for (int i = 0, n = filters.Count; i < n; ++i)
            {
#if (dotNET10 || dotNET11 || dotNETCF10 || dotNETMF)
                IHproseFilter filter = (IHproseFilter)filters[i];
                outData = filter.OutputFilter(outData, context);
#else
                outData = filters[i].OutputFilter(outData, context);
#endif
                outData.Position = 0;
            }
            return(outData);
        }