(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / HttpSimpleWebServiceHandler.cs
blob00d2c25d9f818231dae29fa31d8a4bd5ef82ddf1
1 //
2 // System.Web.Services.Protocols.HttpSimpleWebServiceHandler.cs
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // Copyright (C) Ximian, Inc. 2003
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Reflection;
33 using System.IO;
34 using System.Web.Services;
36 namespace System.Web.Services.Protocols
38 internal class HttpSimpleWebServiceHandler: WebServiceHandler
40 HttpSimpleTypeStubInfo _typeInfo;
41 HttpSimpleMethodStubInfo method;
43 public HttpSimpleWebServiceHandler (Type type, string protocolName)
44 : base (type)
46 _typeInfo = (HttpSimpleTypeStubInfo) TypeStubManager.GetTypeStub (type, protocolName);
49 protected HttpSimpleTypeStubInfo TypeStub
51 get { return _typeInfo; }
54 internal override MethodStubInfo GetRequestMethod (HttpContext context)
56 string name = context.Request.PathInfo;
57 if (name.StartsWith ("/"))
58 name = name.Substring (1);
60 method = (HttpSimpleMethodStubInfo) _typeInfo.GetMethod (name);
61 if (method == null)
62 WriteError (context, "Method " + name + " not defined in service " + ServiceType.Name);
64 return method;
67 public override void ProcessRequest (HttpContext context)
69 Context = context;
70 Stream respStream = null;
71 Exception error = null;
73 try
75 if (method == null)
76 method = (HttpSimpleMethodStubInfo) GetRequestMethod (context);
78 if (method.MethodInfo.EnableSession)
79 Session = context.Session;
81 MimeParameterReader parameterReader = (MimeParameterReader) method.ParameterReaderType.Create ();
82 object[] parameters = parameterReader.Read (context.Request);
84 MimeReturnWriter returnWriter = (MimeReturnWriter) method.ReturnWriterType.Create ();
85 object result = Invoke (method.MethodInfo, parameters);
86 respStream = context.Response.OutputStream;
87 returnWriter.Write (context.Response, respStream, result);
89 catch (Exception ex)
91 error = ex;
94 if (error != null)
95 WriteError (context, error.Message);
97 if (respStream != null)
98 respStream.Close ();
101 void WriteError (HttpContext context, string msg)
105 context.Response.ContentType = "text/plain";
106 context.Response.StatusCode = 500;
107 context.Response.Write (msg);
108 context.Response.End ();
110 catch {}
113 object Invoke (LogicalMethodInfo method, object[] parameters)
117 object server = CreateServerInstance ();
118 object[] res = method.Invoke (server, parameters);
119 if (!method.IsVoid) return res[0];
120 else return null;
122 catch (TargetInvocationException ex)
124 throw ex.InnerException;