2 // Microsoft.Web.Services.Messaging.SoapReceiver.cs
4 // Author: Todd Berman <tberman@gentoo.org>
6 // (C) 2003 Todd Berman
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
)
39 throw new ArgumentNullException ("envelope");
41 SoapReceiver rec
= null;
42 AddressingHeaders header
= null;
46 header
= env
.Context
.Addressing
;
50 if(header
.RelatesTo
!= null || header
.To
!= null || relation
!= 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
);
75 rec
= to
as SoapReceiver
;
77 rec
= (SoapReceiver
) Activator
.CreateInstance (to
as Type
);
80 Exception excep
= null;
82 env
.Context
.SetIsInbound (true);
83 rec
.FilterMessage (env
);
84 } catch (Exception e
) {
88 //FIXME: again, wrong exception type, should be throwing something XmlElement like
89 rec
.Receive (env
, excep
);
95 throw new InvalidOperationException ("no receiver found");
99 throw new InvalidOperationException ("no receiver found pt 2");
102 } catch (Exception e
) {
104 DispatchMessageFault (env
, e
);
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
{
126 protected override void FilterMessage (SoapEnvelope env
)
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
);