Esempio n. 1
0
        protected IAsyncResult BeginInvoke(string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState)
        {
            HttpSimpleMethodStubInfo   method = (HttpSimpleMethodStubInfo)TypeStub.GetMethod(methodName);
            SimpleWebClientAsyncResult ainfo  = null;

            try
            {
                MimeParameterWriter parameterWriter = (MimeParameterWriter)method.ParameterWriterType.Create();
                string     url = parameterWriter.GetRequestUrl(requestUrl, parameters);
                WebRequest req = GetWebRequest(new Uri(url));

                ainfo                 = new SimpleWebClientAsyncResult(req, callback, asyncState);
                ainfo.Parameters      = parameters;
                ainfo.ParameterWriter = parameterWriter;
                ainfo.Method          = method;

                ainfo.Request = req;
                ainfo.Request.BeginGetRequestStream(new AsyncCallback(AsyncGetRequestStreamDone), ainfo);
                RegisterMapping(asyncState, ainfo);
            }
            catch (Exception ex)
            {
                if (ainfo != null)
                {
                    ainfo.SetCompleted(null, ex, false);
                }
                else
                {
                    throw ex;
                }
            }

            return(ainfo);
        }
Esempio n. 2
0
		public override void ProcessRequest (HttpContext context)
		{
			Context = context;
			Stream respStream = null;
			Exception error = null;
			
			try
			{
				if (method == null) 
					method = (HttpSimpleMethodStubInfo) GetRequestMethod (context);

				if (method.MethodInfo.EnableSession)
					Session = context.Session;
			
				MimeParameterReader parameterReader = (MimeParameterReader) method.ParameterReaderType.Create ();
				object[] parameters = parameterReader.Read (context.Request);
		
				MimeReturnWriter returnWriter = (MimeReturnWriter) method.ReturnWriterType.Create ();
				object result = Invoke (method.MethodInfo, parameters);
				respStream = context.Response.OutputStream;
				returnWriter.Write (context.Response, respStream, result);
			}
			catch (Exception ex)
			{
				error = ex;
			}
			
			if (error != null)
				WriteError (context, error.ToString ());
			
			if (respStream != null)
				respStream.Close ();
		}
        void AddType(Hashtable types, Type type, HttpSimpleMethodStubInfo method)
        {
            ArrayList list = (ArrayList)types [type];

            if (list == null)
            {
                list         = new ArrayList();
                types [type] = list;
            }
            list.Add(method);
        }
Esempio n. 4
0
		internal override MethodStubInfo GetRequestMethod (HttpContext context)
		{
			string name = context.Request.PathInfo;
			if (name.StartsWith ("/"))
				name = name.Substring (1);

			method = (HttpSimpleMethodStubInfo) _typeInfo.GetMethod (name);
			if (method == null) 
				WriteError (context, "Method " + name + " not defined in service " + ServiceType.Name);
			
			return method;
		}
Esempio n. 5
0
        internal override MethodStubInfo GetRequestMethod(HttpContext context)
        {
            string name = context.Request.PathInfo;

            if (name.StartsWith("/"))
            {
                name = name.Substring(1);
            }

            method = (HttpSimpleMethodStubInfo)_typeInfo.GetMethod(name);
            if (method == null)
            {
                WriteError(context, "Method " + name + " not defined in service " + ServiceType.Name);
            }

            return(method);
        }
Esempio n. 6
0
        public override void ProcessRequest(HttpContext context)
        {
            Context = context;
            Stream    respStream = null;
            Exception error      = null;

            try
            {
                if (method == null)
                {
                    method = (HttpSimpleMethodStubInfo)GetRequestMethod(context);
                }

                if (method.MethodInfo.EnableSession)
                {
                    Session = context.Session;
                }

                MimeParameterReader parameterReader = (MimeParameterReader)method.ParameterReaderType.Create();
                object[]            parameters      = parameterReader.Read(context.Request);

                MimeReturnWriter returnWriter = (MimeReturnWriter)method.ReturnWriterType.Create();
                object           result       = Invoke(method.MethodInfo, parameters);
                respStream = context.Response.OutputStream;
                returnWriter.Write(context.Response, respStream, result);
            }
            catch (Exception ex)
            {
                error = ex;
            }

            if (error != null)
            {
                WriteError(context, error.ToString());
            }

            if (respStream != null)
            {
                respStream.Close();
            }
        }
Esempio n. 7
0
        protected object Invoke(string methodName, string requestUrl, object[] parameters)
        {
            HttpSimpleMethodStubInfo method          = (HttpSimpleMethodStubInfo)TypeStub.GetMethod(methodName);
            MimeParameterWriter      parameterWriter = (MimeParameterWriter)method.ParameterWriterType.Create();

            string     url     = parameterWriter.GetRequestUrl(requestUrl, parameters);
            WebRequest request = GetWebRequest(new Uri(url, true));

            parameterWriter.InitializeRequest(request, parameters);

            if (parameterWriter.UsesWriteRequest)
            {
                Stream stream = request.GetRequestStream();
                parameterWriter.WriteRequest(stream, parameters);
                stream.Close();
            }

            WebResponse response = GetWebResponse(request);

            MimeReturnReader returnReader = (MimeReturnReader)method.ReturnReaderType.Create();

            return(returnReader.Read(response, response.GetResponseStream()));
        }
Esempio n. 8
0
		void AddType (Hashtable types, Type type, HttpSimpleMethodStubInfo method)
		{
			ArrayList list = (ArrayList) types [type];
			if (list == null)
			{
				list = new ArrayList ();
				types [type] = list;
			}
			list.Add (method);
		}