2 // System.Web.Services.Protocols.HttpSimpleWebServiceHandler.cs
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // Copyright (C) Ximian, Inc. 2003
11 using System.Reflection;
13 using System.Web.Services;
15 namespace System.Web.Services.Protocols
17 internal class HttpSimpleWebServiceHandler: WebServiceHandler
19 HttpSimpleTypeStubInfo _typeInfo;
21 public HttpSimpleWebServiceHandler (Type type, string protocolName): base (type)
23 _typeInfo = (HttpSimpleTypeStubInfo) TypeStubManager.GetTypeStub (type, protocolName);
26 protected HttpSimpleTypeStubInfo TypeStub
28 get { return _typeInfo; }
31 public override void ProcessRequest (HttpContext context)
33 string name = context.Request.PathInfo;
34 if (name.StartsWith ("/")) name = name.Substring (1);
36 Stream respStream = null;
37 Exception error = null;
40 HttpSimpleMethodStubInfo method = (HttpSimpleMethodStubInfo) _typeInfo.GetMethod (name);
41 if (method == null) throw new InvalidOperationException ("Method " + name + " not defined in service " + ServiceType.Name);
43 MimeParameterReader parameterReader = (MimeParameterReader) method.ParameterReaderType.Create ();
44 object[] parameters = parameterReader.Read (context.Request);
46 MimeReturnWriter returnWriter = (MimeReturnWriter) method.ReturnWriterType.Create ();
47 object result = Invoke (method.MethodInfo, parameters);
48 respStream = context.Response.OutputStream;
49 returnWriter.Write (context.Response, respStream, result);
60 context.Response.ContentType = "text/plain";
61 context.Response.StatusCode = 500;
62 context.Response.Write (error.Message);
67 if (respStream != null)
71 object Invoke (LogicalMethodInfo method, object[] parameters)
75 object server = CreateServerInstance ();
76 object[] res = method.Invoke (server, parameters);
77 if (!method.IsVoid) return res[0];
80 catch (TargetInvocationException ex)
82 throw ex.InnerException;