private IMessage DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
 {
     IMessage message;
     string str2;
     string str3;
     Header[] h = new Header[] { new Header("__TypeName", mcm.TypeName), new Header("__MethodName", mcm.MethodName), new Header("__MethodSignature", mcm.MethodSignature) };
     string contentType = headers["Content-Type"] as string;
     HttpChannelHelper.ParseContentType(contentType, out str2, out str3);
     if (string.Compare(str2, "text/xml", StringComparison.Ordinal) == 0)
     {
         message = CoreChannel.DeserializeSoapResponseMessage(stream, mcm, h, this._strictBinding);
     }
     else
     {
         int count = 0x400;
         byte[] buffer = new byte[count];
         StringBuilder builder = new StringBuilder();
         for (int i = stream.Read(buffer, 0, count); i > 0; i = stream.Read(buffer, 0, count))
         {
             builder.Append(Encoding.ASCII.GetString(buffer, 0, i));
         }
         message = new ReturnMessage(new RemotingException(builder.ToString()), mcm);
     }
     stream.Close();
     return message;
 }
 private Header[] GetChannelHeaders(ITransportHeaders requestHeaders, out string soapActionToVerify)
 {
     string str3;
     string str4;
     soapActionToVerify = null;
     string uRI = (string) requestHeaders["__RequestUri"];
     string uri = (string) requestHeaders["SOAPAction"];
     if (uri == null)
     {
         throw new RemotingException(CoreChannel.GetResourceString("Remoting_SoapActionMissing"));
     }
     uri = HttpEncodingHelper.DecodeUri(uri);
     soapActionToVerify = uri;
     if (!SoapServices.GetTypeAndMethodNameFromSoapAction(uri, out str3, out str4))
     {
         Type serverTypeForUri = RemotingServices.GetServerTypeForUri(uRI);
         if (serverTypeForUri == null)
         {
             throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_TypeNotFoundFromUri"), new object[] { uRI }));
         }
         str3 = "clr:" + serverTypeForUri.FullName + ", " + serverTypeForUri.Assembly.GetName().Name;
     }
     else
     {
         str3 = "clr:" + str3;
     }
     int num = 2;
     Header[] headerArray = new Header[num];
     headerArray[0] = new Header("__Uri", uRI);
     headerArray[1] = new Header("__TypeName", str3);
     return headerArray;
 }
 public MethodCall(Header[] h1)
 {
     this.Init();
     this.fSoap = true;
     this.FillHeaders(h1);
     this.ResolveMethod();
 }
Beispiel #4
0
		public void Serialize(Stream serializationStream, object graph, Header[] headers) {
			if(serializationStream == null)
				throw new ArgumentNullException("serializationStream");
			if(!serializationStream.CanWrite)
				throw new SerializationException("Can't write in the serialization stream");
			if(graph == null)
				throw new ArgumentNullException("graph");
			SoapWriter soapWriter = new SoapWriter(serializationStream, _selector, _context, _topObject);
			soapWriter.Serialize (graph, headers, _typeFormat, _assemblyFormat);
		}
        ConsumeContext IMessageDeserializer.Deserialize(ReceiveContext receiveContext)
        {
            object obj;
            var headers = new Header[0];
            using (Stream body = receiveContext.GetBody())
            {
                obj = _formatter.Deserialize(body, x => headers = x);
            }

            return new StaticConsumeContext(_sendEndpointProvider, _publishEndpoint, receiveContext, obj, headers);
        }
Beispiel #6
0
		public MethodCall (Header [] h1)
		{
			Init();

			if (h1 == null || h1.Length == 0) return;

			foreach (Header header in h1)
				InitMethodProperty (header.Name, header.Value);

			ResolveMethod ();
		}
	// Constructors.
	public MethodCall(Header[] h1)
			{
				isSoap = true;		// This form is used for SOAP requests.
				Init();
				if(h1 != null)
				{
					foreach(Header h in h1)
					{
						ProcessHeader(h.Name, h.Value);
					}
				}
				ResolveMethod();
				AccessCheck();
			}
 public void Serialize(Stream serializationStream, object graph, Header[] headers)
 {
     if (serializationStream == null)
     {
         throw new ArgumentNullException("serializationStream");
     }
     InternalFE formatterEnums = new InternalFE {
         FEtypeFormat = this.m_typeFormat,
         FEtopObject = this.m_topObject,
         FEserializerTypeEnum = InternalSerializerTypeE.Soap,
         FEassemblyFormat = this.m_assemblyFormat
     };
     new ObjectWriter(serializationStream, this.m_surrogates, this.m_context, formatterEnums).Serialize(graph, headers, new SoapWriter(serializationStream));
 }
Beispiel #9
0
		public MethodResponse (Header[] h1, IMethodCallMessage mcm)
		{
			if (mcm != null)
			{
				_methodName = mcm.MethodName;
				_uri = mcm.Uri;
				_typeName = mcm.TypeName;
				_methodBase = mcm.MethodBase;
				_methodSignature = (Type[]) mcm.MethodSignature;
				_args = mcm.Args;
			}

			if (h1 != null)
			{
				foreach (Header header in h1)
					InitMethodProperty (header.Name, header.Value);
			}
		}
Beispiel #10
0
        internal void Serialize(Stream serializationStream, object graph, Header[] headers, bool check)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat = _assemblyFormat,
            };

            var sow = new ObjectWriter(_surrogates, _context, formatterEnums, _binder);
            BinaryFormatterWriter binaryWriter = new BinaryFormatterWriter(serializationStream, sow, _typeFormat);
            sow.Serialize(graph, headers, binaryWriter, check);
            _crossAppDomainArray = sow._crossAppDomainArray;
        }
	// Constructors.
	public MethodResponse(Header[] h1, IMethodCallMessage mcm)
			{
				isSoap = true;		// This form is used for SOAP requests.
				if(mcm == null)
				{
					throw new ArgumentNullException("mcm");
				}
				methodName = mcm.MethodName;
				typeName = mcm.TypeName;
				method = mcm.MethodBase;
				hasVarArgs = mcm.HasVarArgs;
				if(h1 != null)
				{
					foreach(Header header in h1)
					{
						ProcessHeader(header.Name, header.Value);
					}
				}
			}
 public MethodResponse(Header[] h1, IMethodCallMessage mcm)
 {
     if (mcm == null)
     {
         throw new ArgumentNullException("mcm");
     }
     Message message = mcm as Message;
     if (message != null)
     {
         this.MI = message.GetMethodBase();
     }
     else
     {
         this.MI = mcm.MethodBase;
     }
     if (this.MI == null)
     {
         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_MethodMissing"), new object[] { mcm.MethodName, mcm.TypeName }));
     }
     this._methodCache = InternalRemotingServices.GetReflectionCachedData(this.MI);
     this.argCount = this._methodCache.Parameters.Length;
     this.fSoap = true;
     this.FillHeaders(h1);
 }
Beispiel #13
0
		public void ReadObjectGraph (BinaryElement elem, BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
		{
			headers = null;

			// Reads the objects. The first object in the stream is the
			// root object.
			bool next = ReadNextObject (elem, reader);
			if (next) {
				do {
					if (readHeaders && (headers == null))
						headers = (Header[])CurrentObject;
					else
						if (_rootObjectID == 0) _rootObjectID = _lastObjectID;
				} while (ReadNextObject (reader));
			}

			result = _manager.GetObject (_rootObjectID);
		}
Beispiel #14
0
		public void ReadObjectGraph (BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
		{
			BinaryElement elem = (BinaryElement)reader.ReadByte ();
			ReadObjectGraph (elem, reader, readHeaders, out result, out headers);
		}
		public void WriteObjectGraph (BinaryWriter writer, object obj, Header[] headers)
		{
			_pendingObjects.Clear();
			if (headers != null) QueueObject (headers);
			QueueObject (obj);
			WriteQueuedObjects (writer);
			WriteSerializationEnd (writer);
			_manager.RaiseOnSerializedEvent ();
		}
        // Commences the process of serializing the entire graph.  All of the data (in the appropriate format
        // is emitted onto the stream).
        internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck)
        {
            if (serializationStream==null)
            {
                throw new ArgumentNullException("serializationStream", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentNull_WithParamName"),serializationStream));             
            }
            SerTrace.Log(this, "Serialize Entry");

            InternalFE formatterEnums = new InternalFE();
            formatterEnums.FEtypeFormat = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat = m_assemblyFormat;    

            ObjectWriter sow = new ObjectWriter(m_surrogates, m_context, formatterEnums);
            __BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat); 
            sow.Serialize(graph, headers, binaryWriter, fCheck);
            m_crossAppDomainArray = sow.crossAppDomainArray;
        }
 // Commences the process of serializing the entire graph.  All of the data (in the appropriate format
 // is emitted onto the stream).
 public void Serialize(Stream serializationStream, Object graph, Header[] headers)
 {
     Serialize(serializationStream, graph, headers, true);
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void PropagateIncomingHeadersToCallContext(IMessage msg)
        {                  
            BCLDebug.Assert(msg != null, "Why is the message null?");

            // If it's an internal message, we can quickly tell if there are any
            //   headers.
            IInternalMessage iim = msg as IInternalMessage;
            if (iim != null)
            {
                if (!iim.HasProperties())
                {
                    // If there are no properties just return immediately.
                    return;
                }
            }
            
            IDictionary properties = msg.Properties;
            BCLDebug.Assert(properties != null, "Why are the properties null?");
            
            IDictionaryEnumerator e = (IDictionaryEnumerator) properties.GetEnumerator();

            // cycle through the properties to get a count of the headers
            int count = 0;
            while (e.MoveNext())
            {   
                String key = (String)e.Key;
                if (!key.StartsWith("__", StringComparison.Ordinal)) 
                {
                    // We don't want to have to check for special values, so we
                    //   blanketly state that header names can't start with
                    //   double underscore.
                    if (e.Value is Header)
                        count++;
                }
            }

            // If there are headers, create array and set it to the received header property
            Header[] headers = null;
            if (count > 0)
            {
                headers = new Header[count];

                count = 0;
                e.Reset();
                while (e.MoveNext())
                {   
                    String key = (String)e.Key;
                    if (!key.StartsWith("__", StringComparison.Ordinal)) 
                    {
                        Header header = e.Value as Header;
                        if (header != null)
                            headers[count++] = header;
                    }
                }                
            }   

            _recvHeaders = headers;
            _sendHeaders = null;
        } // PropagateIncomingHeadersToCallContext
        } // InternalGetOutgoingHeaders


        internal void InternalSetHeaders(Header[] headers)
        {
            _sendHeaders = headers;
            _recvHeaders = null;
        } // InternalSetHeaders
 internal void PropagateIncomingHeadersToCallContext(IMessage msg)
 {
     IInternalMessage message = msg as IInternalMessage;
     if ((message == null) || message.HasProperties())
     {
         IDictionaryEnumerator enumerator = msg.Properties.GetEnumerator();
         int num = 0;
         while (enumerator.MoveNext())
         {
             string key = (string) enumerator.Key;
             if (!key.StartsWith("__", StringComparison.Ordinal) && (enumerator.Value is Header))
             {
                 num++;
             }
         }
         Header[] headerArray = null;
         if (num > 0)
         {
             headerArray = new Header[num];
             num = 0;
             enumerator.Reset();
             while (enumerator.MoveNext())
             {
                 string str2 = (string) enumerator.Key;
                 if (!str2.StartsWith("__", StringComparison.Ordinal))
                 {
                     Header header = enumerator.Value as Header;
                     if (header != null)
                     {
                         headerArray[num++] = header;
                     }
                 }
             }
         }
         this._recvHeaders = headerArray;
         this._sendHeaders = null;
     }
 }
 internal static string GetPropertyKeyForHeader(Header header)
 {
     if (header == null)
     {
         return null;
     }
     if (header.HeaderNamespace != null)
     {
         return (header.Name + ", " + header.HeaderNamespace);
     }
     return header.Name;
 }
Beispiel #22
0
        // ProtocolRequestToMessage
        //
        // Converts an incoming Ice Protocol Request stream from requestStream
        // into a new IMethodCallMessage.  isBatched specifies if the request
        // is a batched request or not.
        public static IMessage ProtocolRequestToMessage(Stream requestStream, bool isBatched)
        {
            Ice.ProtocolReader pr = new Ice.ProtocolReader(requestStream);

            Ice.Identity id;
            string       methodname;
            int          requestId;

            Ice.OperationMode mode;
            Ice.Context       context;


            if (!isBatched)
            {
                Ice.MessageRequest req = pr.ReadMessageRequest();
                requestId  = req.requestId;
                id         = req.id;
                methodname = req.operation;
                mode       = (Ice.OperationMode)Enum.ToObject(typeof(Ice.OperationMode), req.mode);
                context    = req.context;
            }
            else
            {
                Ice.MessageBatchRequest req = pr.ReadMessageBatchRequest();
                requestId  = 0;
                id         = req.id;
                methodname = req.operation;
                mode       = (Ice.OperationMode)Enum.ToObject(typeof(Ice.OperationMode), req.mode);
                context    = req.context;

                // FIXME -- if this is a batch, we really want to return multiple
                // messages.  We need to extend both this function and the callee
                // to understand an array return.
                throw new NotImplementedException("Batch execution detected");
            }

            string uri = id.ToUri();

            Type svrType = RemotingServices.GetServerTypeForUri(uri);

            if (svrType == null)
            {
                throw new RemotingException("No registered server for uri " + uri);
            }

            MethodInfo mi = svrType.GetMethod(methodname);

            if (mi == null)
            {
                throw new Ice.OperationNotExistException();
            }

            int encapsSize = pr.ReadEncapsulationHeader();

            Trace.WriteLine("ProtocolRequestToMessage method: " + methodname + " -> " + mi);

            ParameterInfo[] paramInfos = mi.GetParameters();
            int             inParams = 0, outParams = 0;
            int             readInParams = 0;

            object[] methodArgs;

            if (encapsSize == 0)
            {
                for (int i = 0; i < paramInfos.Length; i++)
                {
                    if (paramInfos[i].IsOut)
                    {
                        outParams++;
                    }
                    else
                    {
                        inParams++;
                    }
                }
                methodArgs = new object[0];
            }
            else
            {
                ArrayList args = new ArrayList();
                for (int i = 0; i < paramInfos.Length; i++)
                {
                    if (!paramInfos[i].IsOut)
                    {
                        object o;
                        if (Attribute.GetCustomAttribute(paramInfos[i], typeof(Ice.AsProxy)) != null)
                        {
                            o = pr.ReadObjectProxy(paramInfos[i].ParameterType);
                            args.Add(o);
                        }
                        else if (!IceByValue(paramInfos[i].ParameterType))
                        {
                            // add a placeholder that will get replaced by
                            // patch call below.
                            args.Add(null);
                            pr.ReadClassInstanceParameterRef(args, readInParams);
                        }
                        else
                        {
                            o = pr.ReadObject(paramInfos[i].ParameterType);
                            args.Add(o);
                        }

                        inParams++;
                        readInParams++;
                    }
                    else
                    {
                        outParams++;
                    }
                }

                pr.ReadClassInstancesAndPatch();

                methodArgs = args.ToArray();
            }

            if (readInParams != inParams)
            {
                // FIXME
                throw new InvalidOperationException("Wrong number of parameters for operation, expected " + inParams + " got " + readInParams);
            }

            // I need: uri, typeNAme, methodName, object[] args
            System.Runtime.Remoting.Messaging.Header[] hs =
                new System.Runtime.Remoting.Messaging.Header[4];
            hs[0] = new Header("__TypeName", svrType.FullName);
            hs[1] = new Header("__MethodName", methodname);
            hs[2] = new Header("__Uri", uri);
            hs[3] = new Header("__Args", methodArgs);

            MethodCall mc = new MethodCall(hs);

            mc.Properties["__iceRequestId"] = requestId;
            mc.Properties["__iceIdentity"]  = id;
            mc.Properties["__iceMode"]      = mode;
            mc.Properties["__iceContext"]   = context;

            return(mc);
        }
 internal void InternalSetHeaders(Header[] headers)
 {
     this._sendHeaders = headers;
     this._recvHeaders = null;
 }
        } // GetHeaders

        public static void SetHeaders(Header[] headers)
        {            
            LogicalCallContext lcc =  Thread.CurrentThread.GetLogicalCallContext();
            lcc.InternalSetHeaders(headers);
        } // SetHeaders
	// Handle incoming headers.
	public virtual Object HeaderHandler(Header[] h)
			{
				// Extract the method name from the headers, if present.
				if(h != null && h.Length != 0 && h[0].Name == "__methodName")
				{
					methodName = (String)(h[0].Value);
					if(h.Length != 1)
					{
						Header[] nh = new Header [h.Length - 1];
						Array.Copy(h, 1, nh, 0, h.Length - 1);
						nh = h;
					}
					else
					{
						h = null;
					}
				}

				// Process the headers to set the message properties.
				if(h != null)
				{
					foreach(Header header in h)
					{
						ProcessHeader(header.Name, header.Value);
					}
				}
				return null;
			}
Beispiel #26
0
		Header[] GetHeaders()
		{
			Header[] hs = null;
			if (useHeaders)
			{
				hs = new Header[1];
				hs[0] = new Header("unom",new SimpleClass('R'));
			}
			return hs;
		}
 [System.Security.SecurityCritical]  // auto-generated
 public static void SetHeaders(Header[] headers)
 {            
     LogicalCallContext lcc =  Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
     lcc.InternalSetHeaders(headers);
 } // SetHeaders
 public virtual new Object HeaderHandler(Header[] h)
 {
   return default(Object);
 }
        } // PropagateOutgoingHeadersToMessage
#endif
        // Retrieve key to use for header.
        internal static String GetPropertyKeyForHeader(Header header)
        {
            if (header == null)
                return null;

            if (header.HeaderNamespace != null)
                return header.Name + ", " + header.HeaderNamespace;
            else
                return header.Name;                
        } // GetPropertyKeyForHeader
 public MethodResponse(Header[] h1, IMethodCallMessage mcm)
 {
 }
		Header DeserializeHeader ()
		{
			Header h = new Header (xmlReader.LocalName, null);
			h.HeaderNamespace = xmlReader.NamespaceURI;
			h.MustUnderstand = xmlReader.GetAttribute ("mustUnderstand", SoapTypeMapper.SoapEnvelopeNamespace) == "1";
			
			object value;
			long fieldId, fieldHref;
			long idHeader = NextAvailableId;
			FieldInfo fieldInfo = typeof(Header).GetField ("Value");

			value = DeserializeComponent (null, out fieldId, out fieldHref, idHeader, fieldInfo, null);
			h.Value = value;

			if(fieldHref != 0 && value == null)
			{
				RecordFixup (idHeader, fieldHref, h, null, null, fieldInfo, null);
			}
			else if(value != null && value.GetType().IsValueType && fieldId != 0)
			{
				RecordFixup (idHeader, fieldId, h, null, null, fieldInfo, null);
			}
			else if(fieldId != 0)
			{
				RegisterObject (fieldId, value, null, idHeader, fieldInfo, null);
			}
			
			RegisterObject (idHeader, h, null, 0, null, null);
			return h;
		}
Beispiel #32
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void PropagateIncomingHeadersToCallContext(IMessage msg)
        {
            BCLDebug.Assert(msg != null, "Why is the message null?");

            // If it's an internal message, we can quickly tell if there are any
            //   headers.
            IInternalMessage iim = msg as IInternalMessage;

            if (iim != null)
            {
                if (!iim.HasProperties())
                {
                    // If there are no properties just return immediately.
                    return;
                }
            }

            IDictionary properties = msg.Properties;

            BCLDebug.Assert(properties != null, "Why are the properties null?");

            IDictionaryEnumerator e = (IDictionaryEnumerator)properties.GetEnumerator();

            // cycle through the properties to get a count of the headers
            int count = 0;

            while (e.MoveNext())
            {
                String key = (String)e.Key;
                if (!key.StartsWith("__", StringComparison.Ordinal))
                {
                    // We don't want to have to check for special values, so we
                    //   blanketly state that header names can't start with
                    //   double underscore.
                    if (e.Value is Header)
                    {
                        count++;
                    }
                }
            }

            // If there are headers, create array and set it to the received header property
            Header[] headers = null;
            if (count > 0)
            {
                headers = new Header[count];

                count = 0;
                e.Reset();
                while (e.MoveNext())
                {
                    String key = (String)e.Key;
                    if (!key.StartsWith("__", StringComparison.Ordinal))
                    {
                        Header header = e.Value as Header;
                        if (header != null)
                        {
                            headers[count++] = header;
                        }
                    }
                }
            }

            _recvHeaders = headers;
            _sendHeaders = null;
        } // PropagateIncomingHeadersToCallContext