**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Messaging / SoapReceiver.cs
blob6a45024ce225247b691743814d2824848909f4b1
1 //
2 // Microsoft.Web.Services.Messaging.SoapReceiver.cs
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
8 using System;
9 using System.Web;
10 using Microsoft.Web.Services;
11 using Microsoft.Web.Services.Addressing;
12 using Microsoft.Web.Services.Configuration;
14 namespace Microsoft.Web.Services.Messaging {
16 public abstract class SoapReceiver : SoapPort, IHttpHandler
19 private static Pipeline _defPipe = new Pipeline ();
21 protected abstract void Receive (SoapEnvelope envelope);
23 public SoapReceiver () : base ()
27 protected void Receive (SoapEnvelope envelope, Exception e)
31 public static void DispatchMessage (SoapEnvelope env)
33 DispatchMessage (env, null);
36 public static void DispatchMessage (SoapEnvelope env, RelatesTo relation)
38 if(env == null) {
39 throw new ArgumentNullException ("envelope");
41 SoapReceiver rec = null;
42 AddressingHeaders header = null;
44 try {
46 header = env.Context.Addressing;
48 header.Load (env);
50 if(header.RelatesTo != null || header.To != null || relation != null)
52 object to = null;
53 if(header.RelatesTo != null) {
54 if(WebServicesConfiguration.MessagingConfiguration.GetTransport (header.RelatesTo.Value.Scheme) == null) {
55 //FIXME: Incorrect exception here, should be using something in Routing.
56 throw new ArgumentException ("Transport " + header.RelatesTo.Value.Scheme + " is not supported");
58 to = SoapReceivers.Receiver (header.RelatesTo.Value);
59 env.Context.SetActor (header.RelatesTo);
61 if(to == null && header.To != null) {
62 if(env.Context.Channel.Scheme != header.To.Value.Scheme) {
63 //FIXME: Incorrect exception again.
64 throw new ArgumentException ("Channel's Scheme and To's Scheme are not the same.");
66 to = SoapReceivers.Receiver (header.To.Value);
67 env.Context.SetActor (header.RelatesTo);
69 if(to == null && relation != null) {
70 to = SoapReceivers.Receiver (relation.Value);
71 env.Context.Addressing.RelatesTo = relation;
72 env.Context.SetActor (relation);
74 if(to != null) {
75 rec = to as SoapReceiver;
76 if(rec == null) {
77 rec = (SoapReceiver) Activator.CreateInstance (to as Type);
79 if(rec != null) {
80 Exception excep = null;
81 try {
82 env.Context.SetIsInbound (true);
83 rec.FilterMessage (env);
84 } catch (Exception e) {
85 excep = e;
87 if(excep != null) {
88 //FIXME: again, wrong exception type, should be throwing something XmlElement like
89 rec.Receive (env, excep);
90 } else {
91 rec.Receive (env);
93 } else {
94 //FIXME: same thing
95 throw new InvalidOperationException ("no receiver found");
97 } else {
98 //FIXME: same
99 throw new InvalidOperationException ("no receiver found pt 2");
102 } catch (Exception e) {
103 if(rec == null) {
104 DispatchMessageFault (env, e);
105 } else {
106 DispatchMessageFault (env, e, rec.Pipeline);
111 public static void DispatchMessageFault (SoapEnvelope env, Exception e)
113 DispatchMessageFault (env, e, _defPipe);
116 public static void DispatchMessageFault (SoapEnvelope env, Exception e, Pipeline pipe)
120 public bool IsReusable {
121 get {
122 return true;
126 protected override void FilterMessage (SoapEnvelope env)
128 if(env == null) {
129 throw new ArgumentNullException ("envelope");
131 Pipeline.ProcessInputMessage (env);
134 public void ProcessSoapRequest (HttpContext context)
139 public void ProcessNonSoapRequest (HttpContext context)
144 public void ProcessRequest (HttpContext context)
146 if(context.Request.HttpMethod == "POST" || context.Request.Headers["SOAPAction"] != null) {
147 ProcessSoapRequest (context);
149 ProcessNonSoapRequest (context);