public virtual object HeaderHandler(Header[] h)
        {
            SerializationMonkey uninitializedObject = (SerializationMonkey)FormatterServices.GetUninitializedObject(typeof(SerializationMonkey));

            Header[] destinationArray = null;
            if (((h != null) && (h.Length > 0)) && (h[0].Name == "__methodName"))
            {
                this.methodName = (string)h[0].Value;
                if (h.Length > 1)
                {
                    destinationArray = new Header[h.Length - 1];
                    Array.Copy(h, 1, destinationArray, 0, h.Length - 1);
                }
                else
                {
                    destinationArray = null;
                }
            }
            else
            {
                destinationArray = h;
            }
            this.FillHeaders(destinationArray, true);
            this.ResolveMethod(false);
            uninitializedObject._obj = this;
            if (this.MI != null)
            {
                ArgMapper mapper = new ArgMapper(this.MI, false);
                uninitializedObject.fieldNames = mapper.ArgNames;
                uninitializedObject.fieldTypes = mapper.ArgTypes;
            }
            return(uninitializedObject);
        }
        public virtual object HeaderHandler(Header[] h)
        {
            SerializationMonkey serializationMonkey = (SerializationMonkey)FormatterServices.GetUninitializedObject(typeof(SerializationMonkey));

            Header[] array;
            if (h != null && h.Length != 0 && h[0].Name == "__methodName")
            {
                this.methodName = (string)h[0].Value;
                if (h.Length > 1)
                {
                    array = new Header[h.Length - 1];
                    Array.Copy(h, 1, array, 0, h.Length - 1);
                }
                else
                {
                    array = null;
                }
            }
            else
            {
                array = h;
            }
            this.FillHeaders(array, true);
            this.ResolveMethod(false);
            serializationMonkey._obj = this;
            if (this.MI != null)
            {
                ArgMapper argMapper = new ArgMapper(this.MI, false);
                serializationMonkey.fieldNames = argMapper.ArgNames;
                serializationMonkey.fieldTypes = argMapper.ArgTypes;
            }
            return(serializationMonkey);
        }
 public object GetOutArg(int argNum)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, true);
     }
     return this._argMapper.GetArg(argNum);
 }
 public string GetOutArgName(int index)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, true);
     }
     return this._argMapper.GetArgName(index);
 }
 public virtual object GetInArg(int argNum)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, false);
     }
     return this._argMapper.GetArg(argNum);
 }
Exemple #6
0
 public object GetOutArg(int argNum)
 {
     if (this.argMapper == null)
     {
         this.argMapper = new ArgMapper((IMethodMessage)this, true);
     }
     return(this.argMapper.GetArg(argNum));
 }
Exemple #7
0
 public object GetInArg(int argNum)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper((IMethodMessage)this, false);
     }
     return(this._argMapper.GetArg(argNum));
 }
 public object GetOutArg(int argNum)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, true);
     }
     return(this._argMapper.GetArg(argNum));
 }
Exemple #9
0
 public string GetOutArgName(int index)
 {
     if (this.argMapper == null)
     {
         this.argMapper = new ArgMapper((IMethodMessage)this, true);
     }
     return(this.argMapper.GetArgName(index));
 }
Exemple #10
0
 public virtual string GetInArgName(int index)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, false);
     }
     return(this._argMapper.GetArgName(index));
 }
 public virtual string GetInArgName(int index)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, false);
     }
     return this._argMapper.GetArgName(index);
 }
Exemple #12
0
 public virtual object GetInArg(int argNum)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, false);
     }
     return(this._argMapper.GetArg(argNum));
 }
 public string GetOutArgName(int index)
 {
     if (this._argMapper == null)
     {
         this._argMapper = new ArgMapper(this, true);
     }
     return(this._argMapper.GetArgName(index));
 }
 public virtual object HeaderHandler(Header[] h)
 {
     SerializationMonkey uninitializedObject = (SerializationMonkey) FormatterServices.GetUninitializedObject(typeof(SerializationMonkey));
     Header[] destinationArray = null;
     if (((h != null) && (h.Length > 0)) && (h[0].Name == "__methodName"))
     {
         this.methodName = (string) h[0].Value;
         if (h.Length > 1)
         {
             destinationArray = new Header[h.Length - 1];
             Array.Copy(h, 1, destinationArray, 0, h.Length - 1);
         }
         else
         {
             destinationArray = null;
         }
     }
     else
     {
         destinationArray = h;
     }
     this.FillHeaders(destinationArray, true);
     this.ResolveMethod(false);
     uninitializedObject._obj = this;
     if (this.MI != null)
     {
         ArgMapper mapper = new ArgMapper(this.MI, false);
         uninitializedObject.fieldNames = mapper.ArgNames;
         uninitializedObject.fieldTypes = mapper.ArgTypes;
     }
     return uninitializedObject;
 }
 internal void SetObjectFromSoapData(SerializationInfo info)
 {
     Hashtable keyToNamespaceTable = (Hashtable) info.GetValue("__keyToNamespaceTable", typeof(Hashtable));
     ArrayList list = (ArrayList) info.GetValue("__paramNameList", typeof(ArrayList));
     SoapFault fault = (SoapFault) info.GetValue("__fault", typeof(SoapFault));
     if (fault != null)
     {
         ServerFault detail = fault.Detail as ServerFault;
         if (detail != null)
         {
             if (detail.Exception != null)
             {
                 this.fault = detail.Exception;
             }
             else
             {
                 Type type = Type.GetType(detail.ExceptionType, false, false);
                 if (type == null)
                 {
                     StringBuilder builder = new StringBuilder();
                     builder.Append("\nException Type: ");
                     builder.Append(detail.ExceptionType);
                     builder.Append("\n");
                     builder.Append("Exception Message: ");
                     builder.Append(detail.ExceptionMessage);
                     builder.Append("\n");
                     builder.Append(detail.StackTrace);
                     this.fault = new ServerException(builder.ToString());
                 }
                 else
                 {
                     object[] args = new object[] { detail.ExceptionMessage };
                     this.fault = (System.Exception) Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, args, null, null);
                 }
             }
         }
         else if (((fault.Detail != null) && (fault.Detail.GetType() == typeof(string))) && (((string) fault.Detail).Length != 0))
         {
             this.fault = new ServerException((string) fault.Detail);
         }
         else
         {
             this.fault = new ServerException(fault.FaultString);
         }
     }
     else
     {
         MethodInfo mI = this.MI as MethodInfo;
         int num = 0;
         if (mI != null)
         {
             Type returnType = mI.ReturnType;
             if (returnType != typeof(void))
             {
                 num++;
                 object obj2 = info.GetValue((string) list[0], typeof(object));
                 if (obj2 is string)
                 {
                     this.retVal = Message.SoapCoerceArg(obj2, returnType, keyToNamespaceTable);
                 }
                 else
                 {
                     this.retVal = obj2;
                 }
             }
         }
         ParameterInfo[] parameters = this._methodCache.Parameters;
         object obj3 = (this.InternalProperties == null) ? null : this.InternalProperties["__UnorderedParams"];
         if (((obj3 != null) && (obj3 is bool)) && ((bool) obj3))
         {
             for (int i = num; i < list.Count; i++)
             {
                 string name = (string) list[i];
                 int index = -1;
                 for (int j = 0; j < parameters.Length; j++)
                 {
                     if (name.Equals(parameters[j].Name))
                     {
                         index = parameters[j].Position;
                     }
                 }
                 if (index == -1)
                 {
                     if (!name.StartsWith("__param", StringComparison.Ordinal))
                     {
                         throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization"));
                     }
                     index = int.Parse(name.Substring(7), CultureInfo.InvariantCulture);
                 }
                 if (index >= this.argCount)
                 {
                     throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization"));
                 }
                 if (this.outArgs == null)
                 {
                     this.outArgs = new object[this.argCount];
                 }
                 this.outArgs[index] = Message.SoapCoerceArg(info.GetValue(name, typeof(object)), parameters[index].ParameterType, keyToNamespaceTable);
             }
         }
         else
         {
             if (this.argMapper == null)
             {
                 this.argMapper = new ArgMapper(this, true);
             }
             for (int k = num; k < list.Count; k++)
             {
                 string str2 = (string) list[k];
                 if (this.outArgs == null)
                 {
                     this.outArgs = new object[this.argCount];
                 }
                 int num6 = this.argMapper.Map[k - num];
                 this.outArgs[num6] = Message.SoapCoerceArg(info.GetValue(str2, typeof(object)), parameters[num6].ParameterType, keyToNamespaceTable);
             }
         }
     }
 }
 public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     if (obj != null && obj != this._rootObj)
     {
         new MessageSurrogate(this._ss).GetObjectData(obj, info, context);
     }
     else
     {
         IMethodReturnMessage methodReturnMessage = obj as IMethodReturnMessage;
         if (methodReturnMessage != null)
         {
             if (methodReturnMessage.Exception == null)
             {
                 MethodBase          methodBase          = methodReturnMessage.MethodBase;
                 SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)methodBase);
                 string    responseXmlElementName        = soapMethodAttribute.ResponseXmlElementName;
                 string    responseXmlNamespace          = soapMethodAttribute.ResponseXmlNamespace;
                 string    returnXmlElementName          = soapMethodAttribute.ReturnXmlElementName;
                 ArgMapper argMapper = new ArgMapper((IMethodMessage)methodReturnMessage, true);
                 object[]  args      = argMapper.Args;
                 info.FullTypeName = responseXmlElementName;
                 info.AssemblyName = responseXmlNamespace;
                 Type returnType = ((MethodInfo)methodBase).ReturnType;
                 if (!(returnType == (Type)null) && !(returnType == SoapMessageSurrogate._voidType))
                 {
                     info.AddValue(returnXmlElementName, methodReturnMessage.ReturnValue, returnType);
                 }
                 if (args == null)
                 {
                     return;
                 }
                 Type[] argTypes = argMapper.ArgTypes;
                 for (int argNum = 0; argNum < args.Length; ++argNum)
                 {
                     string name = argMapper.GetArgName(argNum);
                     if (name == null || name.Length == 0)
                     {
                         name = "__param" + (object)argNum;
                     }
                     info.AddValue(name, args[argNum], argTypes[argNum].IsByRef ? argTypes[argNum].GetElementType() : argTypes[argNum]);
                 }
             }
             else
             {
                 object data  = CallContext.GetData("__ClientIsClr");
                 bool   flag1 = data == null || (bool)data;
                 info.FullTypeName = "FormatterWrapper";
                 info.AssemblyName = this.DefaultFakeRecordAssemblyName;
                 Exception     exception     = methodReturnMessage.Exception;
                 StringBuilder stringBuilder = new StringBuilder();
                 bool          flag2         = false;
                 for (; exception != null; exception = exception.InnerException)
                 {
                     if (exception.Message.StartsWith("MustUnderstand", StringComparison.Ordinal))
                     {
                         flag2 = true;
                     }
                     stringBuilder.Append(" **** ");
                     stringBuilder.Append(exception.GetType().FullName);
                     stringBuilder.Append(" - ");
                     stringBuilder.Append(exception.Message);
                 }
                 ServerFault serverFault = !flag1 ? new ServerFault(methodReturnMessage.Exception.GetType().AssemblyQualifiedName, stringBuilder.ToString(), methodReturnMessage.Exception.StackTrace) : new ServerFault(methodReturnMessage.Exception);
                 string      faultCode   = "Server";
                 if (flag2)
                 {
                     faultCode = "MustUnderstand";
                 }
                 SoapFault soapFault = new SoapFault(faultCode, stringBuilder.ToString(), (string)null, serverFault);
                 info.AddValue("__WrappedObject", (object)soapFault, SoapMessageSurrogate._soapFaultType);
             }
         }
         else
         {
             IMethodCallMessage m                      = (IMethodCallMessage)obj;
             MethodBase         methodBase             = m.MethodBase;
             string             namespaceForMethodCall = SoapServices.GetXmlNamespaceForMethodCall(methodBase);
             object[]           inArgs                 = m.InArgs;
             string[]           inArgNames             = this.GetInArgNames(m, inArgs.Length);
             Type[]             typeArray              = (Type[])m.MethodSignature;
             info.FullTypeName = m.MethodName;
             info.AssemblyName = namespaceForMethodCall;
             int[] marshalRequestArgMap = InternalRemotingServices.GetReflectionCachedData(methodBase).MarshalRequestArgMap;
             for (int index1 = 0; index1 < inArgs.Length; ++index1)
             {
                 string name   = inArgNames[index1] == null || inArgNames[index1].Length == 0 ? "__param" + (object)index1 : inArgNames[index1];
                 int    index2 = marshalRequestArgMap[index1];
                 Type   type   = !typeArray[index2].IsByRef ? typeArray[index2] : typeArray[index2].GetElementType();
                 info.AddValue(name, inArgs[index1], type);
             }
         }
     }
 }
        [System.Security.SecurityCritical]  // auto-generated_required
        public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
        {
            if (info==null) 
            {
               throw new ArgumentNullException("info");
            }
            Contract.EndContractBlock();
                        
            if ( (obj!=null) && (obj !=_rootObj))
            {
                (new MessageSurrogate(_ss)).GetObjectData(obj, info, context);
            }
            else 
            {
                IMethodReturnMessage msg = obj as IMethodReturnMessage;
                if(null != msg)
                {

                    if (msg.Exception == null)
                    {
                        String responseElementName;
                        String responseElementNS;
                        String returnElementName;                    

                        // obtain response element name namespace
                        MethodBase mb = msg.MethodBase;
                        SoapMethodAttribute attr = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb);
                        responseElementName = attr.ResponseXmlElementName;
                        responseElementNS = attr.ResponseXmlNamespace;
                        returnElementName = attr.ReturnXmlElementName;

                        ArgMapper mapper = new ArgMapper(msg, true /*fOut*/);
                        Object[] args = mapper.Args;
                        info.FullTypeName = responseElementName;
                        info.AssemblyName = responseElementNS;
                        Type retType = ((MethodInfo)mb).ReturnType;                                         
                        if (!((retType == null) || (retType == _voidType)))
                        {
                            info.AddValue(returnElementName, msg.ReturnValue, retType);
                        }
                        if (args != null)
                        {
                            Type[] types = mapper.ArgTypes;
                            for (int i=0; i<args.Length; i++)
                            {
                                String name;
                                name = mapper.GetArgName(i);
                                if ((name == null) || (name.Length == 0))
                                {
                                    name = "__param" + i;
                                }
                                info.AddValue(
                                        name, 
                                        args[i], 
                                        types[i].IsByRef?
                                            types[i].GetElementType():types[i]);
                            }
                        }
                    }
                    else
                    {
                        Object oClientIsClr = CallContext.GetData("__ClientIsClr");
                        bool bClientIsClr = (oClientIsClr == null) ? true:(bool)oClientIsClr;
                        info.FullTypeName = "FormatterWrapper";
                        info.AssemblyName = DefaultFakeRecordAssemblyName;

                        Exception ex = msg.Exception;
                        StringBuilder sb = new StringBuilder();
                        bool bMustUnderstandError = false;
                        while(ex != null)
                        {
                            if (ex.Message.StartsWith("MustUnderstand", StringComparison.Ordinal))
                                bMustUnderstandError = true;

                            sb.Append(" **** ");
                            sb.Append(ex.GetType().FullName); 
                            sb.Append(" - ");
                            sb.Append(ex.Message);
                            
                            ex = ex.InnerException;
                        }

                        ServerFault serverFault = null;
                        if (bClientIsClr)
                            serverFault = new ServerFault(msg.Exception); // Clr is the Client use full exception
                        else
                            serverFault = new ServerFault(msg.Exception.GetType().AssemblyQualifiedName, sb.ToString(), msg.Exception.StackTrace); 

                        String faultType = "Server";
                        if (bMustUnderstandError)
                            faultType = "MustUnderstand";

                        SoapFault soapFault = new SoapFault(faultType, sb.ToString(), null, serverFault);
                        info.AddValue("__WrappedObject", soapFault, _soapFaultType);                   
                    }
                }
                else
                {

                    IMethodCallMessage mcm = (IMethodCallMessage)obj;

                    // obtain method namespace        
                    MethodBase mb = mcm.MethodBase;                
                    String methodElementNS = SoapServices.GetXmlNamespaceForMethodCall(mb);       

                    Object[] args = mcm.InArgs;
                    String[] names = GetInArgNames(mcm, args.Length);
                    Type[] sig = (Type[])mcm.MethodSignature;
                    info.FullTypeName = mcm.MethodName;
                    info.AssemblyName = methodElementNS;
                    RemotingMethodCachedData cache = (RemotingMethodCachedData)InternalRemotingServices.GetReflectionCachedData(mb);
                    int[] requestArgMap = cache.MarshalRequestArgMap;


                    Contract.Assert(
                        args!=null || sig.Length == args.Length, 
                        "Signature mismatch");

                    for (int i = 0; i < args.Length; i++)
                    {
                        String paramName = null;
                        if ((names[i] == null) || (names[i].Length == 0))
                            paramName = "__param" + i;
                        else
                            paramName = names[i];

                        int sigPosition = requestArgMap[i];
                        Type argType = null;

                        if (sig[sigPosition].IsByRef)
                            argType = sig[sigPosition].GetElementType();
                        else
                            argType = sig[sigPosition];

                        info.AddValue(paramName, args[i], argType);
                    }
                }
            }
        } // GetObjectData
Exemple #18
0
        } // InArgCount

        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodCallMessageWrapper.GetInArg"]/*' />
	/// <internalonly/>
        public virtual Object  GetInArg(int argNum)   
        {
            if (_argMapper == null) _argMapper = new ArgMapper(this, false);
            return _argMapper.GetArg(argNum);
        } // GetInArg
Exemple #19
0
        internal void SetObjectFromSoapData(SerializationInfo info)
        {
            Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable));
            ArrayList arrayList           = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList));
            SoapFault soapFault           = (SoapFault)info.GetValue("__fault", typeof(SoapFault));

            if (soapFault != null)
            {
                ServerFault serverFault = soapFault.Detail as ServerFault;
                if (serverFault != null)
                {
                    if (serverFault.Exception != null)
                    {
                        this.fault = serverFault.Exception;
                    }
                    else
                    {
                        Type type = Type.GetType(serverFault.ExceptionType, false, false);
                        if (type == (Type)null)
                        {
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.Append("\nException Type: ");
                            stringBuilder.Append(serverFault.ExceptionType);
                            stringBuilder.Append("\n");
                            stringBuilder.Append("Exception Message: ");
                            stringBuilder.Append(serverFault.ExceptionMessage);
                            stringBuilder.Append("\n");
                            stringBuilder.Append(serverFault.StackTrace);
                            this.fault = (Exception) new ServerException(stringBuilder.ToString());
                        }
                        else
                        {
                            object[] args = new object[1] {
                                (object)serverFault.ExceptionMessage
                            };
                            this.fault = (Exception)Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, (Binder)null, args, (CultureInfo)null, (object[])null);
                        }
                    }
                }
                else if (soapFault.Detail != null && soapFault.Detail.GetType() == typeof(string) && ((string)soapFault.Detail).Length != 0)
                {
                    this.fault = (Exception) new ServerException((string)soapFault.Detail);
                }
                else
                {
                    this.fault = (Exception) new ServerException(soapFault.FaultString);
                }
            }
            else
            {
                MethodInfo methodInfo = this.MI as MethodInfo;
                int        num        = 0;
                if (methodInfo != (MethodInfo)null)
                {
                    Type returnType = methodInfo.ReturnType;
                    if (returnType != typeof(void))
                    {
                        ++num;
                        object obj = info.GetValue((string)arrayList[0], typeof(object));
                        this.retVal = !(obj is string) ? obj : Message.SoapCoerceArg(obj, returnType, keyToNamespaceTable);
                    }
                }
                ParameterInfo[] parameters = this._methodCache.Parameters;
                object          obj1       = this.InternalProperties == null ? (object)null : this.InternalProperties[(object)"__UnorderedParams"];
                if (obj1 != null && obj1 is bool && (bool)obj1)
                {
                    for (int index1 = num; index1 < arrayList.Count; ++index1)
                    {
                        string name   = (string)arrayList[index1];
                        int    index2 = -1;
                        for (int index3 = 0; index3 < parameters.Length; ++index3)
                        {
                            if (name.Equals(parameters[index3].Name))
                            {
                                index2 = parameters[index3].Position;
                            }
                        }
                        if (index2 == -1)
                        {
                            if (!name.StartsWith("__param", StringComparison.Ordinal))
                            {
                                throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization"));
                            }
                            index2 = int.Parse(name.Substring(7), (IFormatProvider)CultureInfo.InvariantCulture);
                        }
                        if (index2 >= this.argCount)
                        {
                            throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization"));
                        }
                        if (this.outArgs == null)
                        {
                            this.outArgs = new object[this.argCount];
                        }
                        this.outArgs[index2] = Message.SoapCoerceArg(info.GetValue(name, typeof(object)), parameters[index2].ParameterType, keyToNamespaceTable);
                    }
                }
                else
                {
                    if (this.argMapper == null)
                    {
                        this.argMapper = new ArgMapper((IMethodMessage)this, true);
                    }
                    for (int index1 = num; index1 < arrayList.Count; ++index1)
                    {
                        string name = (string)arrayList[index1];
                        if (this.outArgs == null)
                        {
                            this.outArgs = new object[this.argCount];
                        }
                        int index2 = this.argMapper.Map[index1 - num];
                        this.outArgs[index2] = Message.SoapCoerceArg(info.GetValue(name, typeof(object)), parameters[index2].ParameterType, keyToNamespaceTable);
                    }
                }
            }
        }
 public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     if ((obj != null) && (obj != this._rootObj))
     {
         new MessageSurrogate(this._ss).GetObjectData(obj, info, context);
     }
     else
     {
         IMethodReturnMessage mm = obj as IMethodReturnMessage;
         if (mm != null)
         {
             if (mm.Exception != null)
             {
                 object data = CallContext.GetData("__ClientIsClr");
                 bool flag = (data == null) || ((bool) data);
                 info.FullTypeName = "FormatterWrapper";
                 info.AssemblyName = this.DefaultFakeRecordAssemblyName;
                 Exception innerException = mm.Exception;
                 StringBuilder builder = new StringBuilder();
                 bool flag2 = false;
                 while (innerException != null)
                 {
                     if (innerException.Message.StartsWith("MustUnderstand", StringComparison.Ordinal))
                     {
                         flag2 = true;
                     }
                     builder.Append(" **** ");
                     builder.Append(innerException.GetType().FullName);
                     builder.Append(" - ");
                     builder.Append(innerException.Message);
                     innerException = innerException.InnerException;
                 }
                 ServerFault serverFault = null;
                 if (flag)
                 {
                     serverFault = new ServerFault(mm.Exception);
                 }
                 else
                 {
                     serverFault = new ServerFault(mm.Exception.GetType().AssemblyQualifiedName, builder.ToString(), mm.Exception.StackTrace);
                 }
                 string faultCode = "Server";
                 if (flag2)
                 {
                     faultCode = "MustUnderstand";
                 }
                 SoapFault fault2 = new SoapFault(faultCode, builder.ToString(), null, serverFault);
                 info.AddValue("__WrappedObject", fault2, _soapFaultType);
             }
             else
             {
                 MethodBase methodBase = mm.MethodBase;
                 SoapMethodAttribute cachedSoapAttribute = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(methodBase);
                 string responseXmlElementName = cachedSoapAttribute.ResponseXmlElementName;
                 string responseXmlNamespace = cachedSoapAttribute.ResponseXmlNamespace;
                 string returnXmlElementName = cachedSoapAttribute.ReturnXmlElementName;
                 ArgMapper mapper = new ArgMapper(mm, true);
                 object[] args = mapper.Args;
                 info.FullTypeName = responseXmlElementName;
                 info.AssemblyName = responseXmlNamespace;
                 Type returnType = ((MethodInfo) methodBase).ReturnType;
                 if ((returnType != null) && !(returnType == _voidType))
                 {
                     info.AddValue(returnXmlElementName, mm.ReturnValue, returnType);
                 }
                 if (args != null)
                 {
                     Type[] argTypes = mapper.ArgTypes;
                     for (int i = 0; i < args.Length; i++)
                     {
                         string argName = mapper.GetArgName(i);
                         if ((argName == null) || (argName.Length == 0))
                         {
                             argName = "__param" + i;
                         }
                         info.AddValue(argName, args[i], argTypes[i].IsByRef ? argTypes[i].GetElementType() : argTypes[i]);
                     }
                 }
             }
         }
         else
         {
             IMethodCallMessage m = (IMethodCallMessage) obj;
             MethodBase mb = m.MethodBase;
             string xmlNamespaceForMethodCall = SoapServices.GetXmlNamespaceForMethodCall(mb);
             object[] inArgs = m.InArgs;
             string[] inArgNames = this.GetInArgNames(m, inArgs.Length);
             Type[] methodSignature = (Type[]) m.MethodSignature;
             info.FullTypeName = m.MethodName;
             info.AssemblyName = xmlNamespaceForMethodCall;
             int[] marshalRequestArgMap = InternalRemotingServices.GetReflectionCachedData(mb).MarshalRequestArgMap;
             for (int j = 0; j < inArgs.Length; j++)
             {
                 string name = null;
                 if ((inArgNames[j] == null) || (inArgNames[j].Length == 0))
                 {
                     name = "__param" + j;
                 }
                 else
                 {
                     name = inArgNames[j];
                 }
                 int index = marshalRequestArgMap[j];
                 Type type = null;
                 if (methodSignature[index].IsByRef)
                 {
                     type = methodSignature[index].GetElementType();
                 }
                 else
                 {
                     type = methodSignature[index];
                 }
                 info.AddValue(name, inArgs[j], type);
             }
         }
     }
 }
Exemple #21
0
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodReturnMessageWrapper.GetOutArgName"]/*' />
	/// <internalonly/>
        public virtual String GetOutArgName(int index) 
        { 
            if (_argMapper == null) _argMapper = new ArgMapper(this, true);
            return _argMapper.GetArgName(index);
        }
Exemple #22
0
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodReturnMessageWrapper.GetOutArg"]/*' />
	/// <internalonly/>
        public virtual Object  GetOutArg(int argNum)   
        {   
            if (_argMapper == null) _argMapper = new ArgMapper(this, true);
            return _argMapper.GetArg(argNum);
        }
Exemple #23
0
        } // GetInArg
        
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodCallMessageWrapper.GetInArgName"]/*' />
	/// <internalonly/>
        public virtual String GetInArgName(int index) 
        { 
            if (_argMapper == null) _argMapper = new ArgMapper(this, false);
            return _argMapper.GetArgName(index);
        } // GetInArgName
Exemple #24
0
        internal void SetObjectFromSoapData(SerializationInfo info)
        {
            Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable));
            ArrayList list  = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList));
            SoapFault fault = (SoapFault)info.GetValue("__fault", typeof(SoapFault));

            if (fault != null)
            {
                ServerFault detail = fault.Detail as ServerFault;
                if (detail != null)
                {
                    if (detail.Exception != null)
                    {
                        this.fault = detail.Exception;
                    }
                    else
                    {
                        Type type = Type.GetType(detail.ExceptionType, false, false);
                        if (type == null)
                        {
                            StringBuilder builder = new StringBuilder();
                            builder.Append("\nException Type: ");
                            builder.Append(detail.ExceptionType);
                            builder.Append("\n");
                            builder.Append("Exception Message: ");
                            builder.Append(detail.ExceptionMessage);
                            builder.Append("\n");
                            builder.Append(detail.StackTrace);
                            this.fault = new ServerException(builder.ToString());
                        }
                        else
                        {
                            object[] args = new object[] { detail.ExceptionMessage };
                            this.fault = (System.Exception)Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, args, null, null);
                        }
                    }
                }
                else if (((fault.Detail != null) && (fault.Detail.GetType() == typeof(string))) && (((string)fault.Detail).Length != 0))
                {
                    this.fault = new ServerException((string)fault.Detail);
                }
                else
                {
                    this.fault = new ServerException(fault.FaultString);
                }
            }
            else
            {
                MethodInfo mI  = this.MI as MethodInfo;
                int        num = 0;
                if (mI != null)
                {
                    Type returnType = mI.ReturnType;
                    if (returnType != typeof(void))
                    {
                        num++;
                        object obj2 = info.GetValue((string)list[0], typeof(object));
                        if (obj2 is string)
                        {
                            this.retVal = Message.SoapCoerceArg(obj2, returnType, keyToNamespaceTable);
                        }
                        else
                        {
                            this.retVal = obj2;
                        }
                    }
                }
                ParameterInfo[] parameters = this._methodCache.Parameters;
                object          obj3       = (this.InternalProperties == null) ? null : this.InternalProperties["__UnorderedParams"];
                if (((obj3 != null) && (obj3 is bool)) && ((bool)obj3))
                {
                    for (int i = num; i < list.Count; i++)
                    {
                        string name  = (string)list[i];
                        int    index = -1;
                        for (int j = 0; j < parameters.Length; j++)
                        {
                            if (name.Equals(parameters[j].Name))
                            {
                                index = parameters[j].Position;
                            }
                        }
                        if (index == -1)
                        {
                            if (!name.StartsWith("__param", StringComparison.Ordinal))
                            {
                                throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization"));
                            }
                            index = int.Parse(name.Substring(7), CultureInfo.InvariantCulture);
                        }
                        if (index >= this.argCount)
                        {
                            throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization"));
                        }
                        if (this.outArgs == null)
                        {
                            this.outArgs = new object[this.argCount];
                        }
                        this.outArgs[index] = Message.SoapCoerceArg(info.GetValue(name, typeof(object)), parameters[index].ParameterType, keyToNamespaceTable);
                    }
                }
                else
                {
                    if (this.argMapper == null)
                    {
                        this.argMapper = new ArgMapper(this, true);
                    }
                    for (int k = num; k < list.Count; k++)
                    {
                        string str2 = (string)list[k];
                        if (this.outArgs == null)
                        {
                            this.outArgs = new object[this.argCount];
                        }
                        int num6 = this.argMapper.Map[k - num];
                        this.outArgs[num6] = Message.SoapCoerceArg(info.GetValue(str2, typeof(object)), parameters[num6].ParameterType, keyToNamespaceTable);
                    }
                }
            }
        }
Exemple #25
0
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodResponse.GetOutArg"]/*' />
	/// <internalonly/>
        public Object  GetOutArg(int argNum)   
        {   
            if (argMapper == null) argMapper = new ArgMapper(this, true);
            return argMapper.GetArg(argNum);
        }
Exemple #26
0
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodCall.HeaderHandler"]/*' />
	/// <internalonly/>
        public virtual Object HeaderHandler(Header[] h)
        {
            SerializationMonkey m = (SerializationMonkey) FormatterServices.GetUninitializedObject(typeof(SerializationMonkey));
            Header[] newHeaders = null;
            if (h != null && h.Length > 0 && h[0].Name == "__methodName")
            {
                methodName = (String)h[0].Value;
                if (h.Length > 1)
                {
                    newHeaders = new Header[h.Length -1];
                    Array.Copy(h, 1, newHeaders, 0, h.Length-1);
                }
                else
                    newHeaders = null;
            }
            else
                newHeaders = h;

            FillHeaders(newHeaders, true);
            ResolveMethod(false);
            m._obj = this;
            if (MI != null)
            {
                ArgMapper argm = new ArgMapper(MI, false);
                m.fieldNames = argm.ArgNames;
                m.fieldTypes = argm.ArgTypes;
            }
            return m;
        }
Exemple #27
0
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodResponse.GetOutArgName"]/*' />
	/// <internalonly/>
        public String GetOutArgName(int index) 
        { 
            if (argMapper == null) argMapper = new ArgMapper(this, true);
            return argMapper.GetArgName(index);
        }
Exemple #28
0
        /// <include file='doc\Message.uex' path='docs/doc[@for="MethodCall.GetInArg"]/*' />
	/// <internalonly/>
        public Object  GetInArg(int argNum)   
        {
            if (argMapper == null) argMapper = new ArgMapper(this, false);
            return argMapper.GetArg(argNum);
        }
Exemple #29
0
        //
        // SetObjectFromSoapData -- assumes SOAP format and populates the arguments array
        //

        internal virtual void SetObjectFromSoapData(SerializationInfo info)
        {
            //SerializationInfoEnumerator e = info.GetEnumerator(); 

            Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable));
            ArrayList paramNames = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList));
            SoapFault soapFault = (SoapFault)info.GetValue("__fault", typeof(SoapFault));

            if (soapFault != null)
                    {
                ServerFault serverFault = soapFault.Detail as ServerFault;
				if (null != serverFault)
				{
					// Server Fault information
                    if (serverFault.Exception != null)
                        fault = serverFault.Exception;
                    else
                    {
                        Type exceptionType = RuntimeType.GetTypeInternal(serverFault.ExceptionType, false, false, false);
                        if (exceptionType == null)
                        {
                            // Exception type cannot be resolved, use a ServerException
                            StringBuilder sb = new StringBuilder();
                            sb.Append("\nException Type: ");
                            sb.Append(serverFault.ExceptionType);
                            sb.Append("\n");
                            sb.Append("Exception Message: ");
                            sb.Append(serverFault.ExceptionMessage);
                            sb.Append("\n");
                            sb.Append(serverFault.StackTrace);
                            fault = new ServerException(sb.ToString());
                        }
                        else 
                        {
                            // Exception type can be resolved, throw the exception
                            Object[] args = {serverFault.ExceptionMessage};
                            fault = (Exception)Activator.CreateInstance(
                                                    exceptionType, 
                                                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, 
                                                    null, 
                                                    args, 
                                                    null, 
                                                    null);
                        }
                    }
				}
				else if ((soapFault.Detail != null) && (soapFault.Detail.GetType() == typeof(String)) && (!(((String)soapFault.Detail).Length == 0)))
				{
					fault = new ServerException((String)soapFault.Detail);
				}
				else
				{
					fault = new ServerException(soapFault.FaultString);
				}

                return;
            }

                MethodInfo mi = MI as MethodInfo;
            int paramNameIndex = 0;
                if (mi != null)
                {
				    Type retType = mi.ReturnType;
                if (retType != typeof(void))
                    {
                    paramNameIndex++;
                    Object returnValue = info.GetValue((String)paramNames[0], typeof(Object));
                    if (returnValue is String)
                        retVal = Message.SoapCoerceArg(returnValue, retType, keyToNamespaceTable);
                    else
                        retVal = returnValue;
                    }
                }

                // populate the args array
                ParameterInfo[] pinfos = _methodCache.Parameters;

                Object fUnordered = (InternalProperties == null) ? null : InternalProperties["__UnorderedParams"];
                if (fUnordered != null &&
                    (fUnordered is System.Boolean) && 
                    (true == (bool)fUnordered))
                {
                    // Unordered
                for (int i=paramNameIndex; i<paramNames.Count; i++)
                    {
                    String memberName = (String)paramNames[i];

                        // check for the parameter name

                        int position = -1;
                    for (int j=0; j<pinfos.Length; j++)
                        {
                        if (memberName.Equals(pinfos[j].Name))
                            {
                            position = pinfos[j].Position;
                            }
                        }

                        // no name so check for well known name

                        if (position == -1)
                        {
                            if (!memberName.StartsWith("__param"))
                            {
                                throw new RemotingException(
                                    Environment.GetResourceString(
                                        "Remoting_Message_BadSerialization"));
                            }
                            position = Int32.Parse(memberName.Substring(7));
                        }

                        // if still not resolved then throw

                        if (position >= argCount)
                        {
                            throw new RemotingException(
                                Environment.GetResourceString(
                                    "Remoting_Message_BadSerialization"));
                        }

                        // store the arg in the parameter array

                        if (outArgs == null)
                        {
                            outArgs = new Object[argCount];
                        }
                    outArgs[position]= Message.SoapCoerceArg(info.GetValue(memberName, typeof(Object)), pinfos[position].ParameterType, keyToNamespaceTable);
                    }
                }
                else
                {
                    // ordered
                    if (argMapper == null) argMapper = new ArgMapper(this, true);
                    for (int j=paramNameIndex; j<paramNames.Count; j++)
                    {
                        String memberName = (String)paramNames[j];
                        if (outArgs == null)
                        {
                            outArgs = new Object[argCount];
                        }

                        int position = argMapper.Map[j-paramNameIndex];
                        outArgs[position] = Message.SoapCoerceArg(info.GetValue(memberName, typeof(Object)), pinfos[position].ParameterType, keyToNamespaceTable);
                    }
                }
        } // SetObjectFromSoapData
Exemple #30
0
        public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if ((obj != null) && (obj != _rootObj))
            {
                (new MessageSurrogate(_ss)).GetObjectData(obj, info, context);
            }
            else
            {
                IMethodReturnMessage msg = obj as IMethodReturnMessage;
                if (null != msg)
                {
                    if (msg.Exception == null)
                    {
                        String responseElementName;
                        String responseElementNS;
                        String returnElementName;

                        // obtain response element name namespace
                        MethodBase          mb   = msg.MethodBase;
                        SoapMethodAttribute attr = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb);
                        responseElementName = attr.ResponseXmlElementName;
                        responseElementNS   = attr.ResponseXmlNamespace;
                        returnElementName   = attr.ReturnXmlElementName;

                        ArgMapper mapper = new ArgMapper(msg, true /*fOut*/);
                        Object[]  args   = mapper.Args;
                        info.FullTypeName = responseElementName;
                        info.AssemblyName = responseElementNS;
                        Type retType = ((MethodInfo)mb).ReturnType;
                        if (!((retType == null) || (retType == _voidType)))
                        {
                            info.AddValue(returnElementName, msg.ReturnValue, retType);
                        }
                        if (args != null)
                        {
                            Type[] types = mapper.ArgTypes;
                            for (int i = 0; i < args.Length; i++)
                            {
                                String name;
                                name = mapper.GetArgName(i);
                                if ((name == null) || (name.Length == 0))
                                {
                                    name = "__param" + i;
                                }
                                info.AddValue(
                                    name,
                                    args[i],
                                    types[i].IsByRef?
                                    types[i].GetElementType():types[i]);
                            }
                        }
                    }
                    else
                    {
                        Object oClientIsClr = CallContext.GetData("__ClientIsClr");
                        bool   bClientIsClr = (oClientIsClr == null) ? true:(bool)oClientIsClr;
                        info.FullTypeName = "FormatterWrapper";
                        info.AssemblyName = DefaultFakeRecordAssemblyName;

                        Exception     ex = msg.Exception;
                        StringBuilder sb = new StringBuilder();
                        bool          bMustUnderstandError = false;
                        while (ex != null)
                        {
                            if (ex.Message.StartsWith("MustUnderstand"))
                            {
                                bMustUnderstandError = true;
                            }

                            sb.Append(" **** ");
                            sb.Append(ex.GetType().FullName);
                            sb.Append(" - ");
                            sb.Append(ex.Message);

                            ex = ex.InnerException;
                        }

                        ServerFault serverFault = null;
                        if (bClientIsClr)
                        {
                            serverFault = new ServerFault(msg.Exception); // Clr is the Client use full exception
                        }
                        else
                        {
                            serverFault = new ServerFault(msg.Exception.GetType().AssemblyQualifiedName, sb.ToString(), msg.Exception.StackTrace);
                        }

                        String faultType = "Server";
                        if (bMustUnderstandError)
                        {
                            faultType = "MustUnderstand";
                        }

                        SoapFault soapFault = new SoapFault(faultType, sb.ToString(), null, serverFault);
                        info.AddValue("__WrappedObject", soapFault, _soapFaultType);
                    }
                }
                else
                {
                    IMethodCallMessage mcm = (IMethodCallMessage)obj;

                    // obtain method namespace
                    MethodBase mb = mcm.MethodBase;
                    String     methodElementNS = SoapServices.GetXmlNamespaceForMethodCall(mb);

                    Object[] args  = mcm.InArgs;
                    String[] names = GetInArgNames(mcm, args.Length);
                    Type[]   sig   = (Type[])mcm.MethodSignature;
                    info.FullTypeName = mcm.MethodName;
                    info.AssemblyName = methodElementNS;
                    RemotingMethodCachedData cache = (RemotingMethodCachedData)InternalRemotingServices.GetReflectionCachedData(mb);
                    int[] requestArgMap            = cache.MarshalRequestArgMap;


                    BCLDebug.Assert(
                        args != null || sig.Length == args.Length,
                        "Signature mismatch");

                    for (int i = 0; i < args.Length; i++)
                    {
                        String paramName = null;
                        if ((names[i] == null) || (names[i].Length == 0))
                        {
                            paramName = "__param" + i;
                        }
                        else
                        {
                            paramName = names[i];
                        }

                        int  sigPosition = requestArgMap[i];
                        Type argType     = null;

                        if (sig[sigPosition].IsByRef)
                        {
                            argType = sig[sigPosition].GetElementType();
                        }
                        else
                        {
                            argType = sig[sigPosition];
                        }

                        info.AddValue(paramName, args[i], argType);
                    }
                }
            }
        } // GetObjectData
 public virtual void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     if ((obj != null) && (obj != this._rootObj))
     {
         new MessageSurrogate(this._ss).GetObjectData(obj, info, context);
     }
     else
     {
         IMethodReturnMessage mm = obj as IMethodReturnMessage;
         if (mm != null)
         {
             if (mm.Exception != null)
             {
                 object data = CallContext.GetData("__ClientIsClr");
                 bool   flag = (data == null) || ((bool)data);
                 info.FullTypeName = "FormatterWrapper";
                 info.AssemblyName = this.DefaultFakeRecordAssemblyName;
                 Exception     innerException = mm.Exception;
                 StringBuilder builder        = new StringBuilder();
                 bool          flag2          = false;
                 while (innerException != null)
                 {
                     if (innerException.Message.StartsWith("MustUnderstand", StringComparison.Ordinal))
                     {
                         flag2 = true;
                     }
                     builder.Append(" **** ");
                     builder.Append(innerException.GetType().FullName);
                     builder.Append(" - ");
                     builder.Append(innerException.Message);
                     innerException = innerException.InnerException;
                 }
                 ServerFault serverFault = null;
                 if (flag)
                 {
                     serverFault = new ServerFault(mm.Exception);
                 }
                 else
                 {
                     serverFault = new ServerFault(mm.Exception.GetType().AssemblyQualifiedName, builder.ToString(), mm.Exception.StackTrace);
                 }
                 string faultCode = "Server";
                 if (flag2)
                 {
                     faultCode = "MustUnderstand";
                 }
                 SoapFault fault2 = new SoapFault(faultCode, builder.ToString(), null, serverFault);
                 info.AddValue("__WrappedObject", fault2, _soapFaultType);
             }
             else
             {
                 MethodBase          methodBase          = mm.MethodBase;
                 SoapMethodAttribute cachedSoapAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(methodBase);
                 string    responseXmlElementName        = cachedSoapAttribute.ResponseXmlElementName;
                 string    responseXmlNamespace          = cachedSoapAttribute.ResponseXmlNamespace;
                 string    returnXmlElementName          = cachedSoapAttribute.ReturnXmlElementName;
                 ArgMapper mapper = new ArgMapper(mm, true);
                 object[]  args   = mapper.Args;
                 info.FullTypeName = responseXmlElementName;
                 info.AssemblyName = responseXmlNamespace;
                 Type returnType = ((MethodInfo)methodBase).ReturnType;
                 if ((returnType != null) && !(returnType == _voidType))
                 {
                     info.AddValue(returnXmlElementName, mm.ReturnValue, returnType);
                 }
                 if (args != null)
                 {
                     Type[] argTypes = mapper.ArgTypes;
                     for (int i = 0; i < args.Length; i++)
                     {
                         string argName = mapper.GetArgName(i);
                         if ((argName == null) || (argName.Length == 0))
                         {
                             argName = "__param" + i;
                         }
                         info.AddValue(argName, args[i], argTypes[i].IsByRef ? argTypes[i].GetElementType() : argTypes[i]);
                     }
                 }
             }
         }
         else
         {
             IMethodCallMessage m  = (IMethodCallMessage)obj;
             MethodBase         mb = m.MethodBase;
             string             xmlNamespaceForMethodCall = SoapServices.GetXmlNamespaceForMethodCall(mb);
             object[]           inArgs          = m.InArgs;
             string[]           inArgNames      = this.GetInArgNames(m, inArgs.Length);
             Type[]             methodSignature = (Type[])m.MethodSignature;
             info.FullTypeName = m.MethodName;
             info.AssemblyName = xmlNamespaceForMethodCall;
             int[] marshalRequestArgMap = InternalRemotingServices.GetReflectionCachedData(mb).MarshalRequestArgMap;
             for (int j = 0; j < inArgs.Length; j++)
             {
                 string name = null;
                 if ((inArgNames[j] == null) || (inArgNames[j].Length == 0))
                 {
                     name = "__param" + j;
                 }
                 else
                 {
                     name = inArgNames[j];
                 }
                 int  index = marshalRequestArgMap[j];
                 Type type  = null;
                 if (methodSignature[index].IsByRef)
                 {
                     type = methodSignature[index].GetElementType();
                 }
                 else
                 {
                     type = methodSignature[index];
                 }
                 info.AddValue(name, inArgs[j], type);
             }
         }
     }
 }