485c021051004a0b2cea6f0e812e0ecea3c478cb
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Messaging / SoapSender.cs
1 //
2 // Microsoft.Web.Services.Messaging.SoapSender
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
7
8 using System;
9 using System.Web;
10 using Microsoft.Web.Services;
11 using Microsoft.Web.Services.Addressing;
12 using Microsoft.Web.Services.Configuration;
13
14 namespace Microsoft.Web.Services.Messaging {
15
16         public class SoapSender : SoapPort
17         {
18
19                 private EndpointReference _destination = null;
20                 private ISoapTransport _transport = null;
21                 
22                 public SoapSender () : base ()
23                 {
24                 }
25
26                 public SoapSender (EndpointReference dest) : base ()
27                 {
28                         if(dest == null) {
29                                 throw new ArgumentNullException ("destination");
30                         }
31                         Destination = dest;
32                 }
33
34                 public SoapSender (Uri destination) : this (new EndpointReference (destination))
35                 {
36                 }
37
38                 protected override void FilterMessage (SoapEnvelope env)
39                 {
40                         if(env == null) {
41                                 throw new ArgumentNullException ("envelope");
42                         }
43                         Pipeline.ProcessOutputMessage (env);
44                 }
45
46                 public void Send (SoapEnvelope env)
47                 {
48                         if(env == null) {
49                                 throw new ArgumentNullException ("envelope");
50                         }
51                         if(env.Context.Action == null) {
52                                 throw new ArgumentException ("Action not set");
53                         }
54                         if(env.Processed == true || env.Context.Processed == true) {
55                                 throw new ArgumentException ("Attempting to re-process an envelope");
56                         }
57                         
58                         if(_destination == null) {
59                                 throw new ArgumentException ("Destination is not set, cant send");
60                         }
61                         if(_transport == null) {
62                                 throw new ArgumentException ("Transport is not set, cant send");
63                         }
64
65                         env.Context.SetTo(_destination.Address);
66
67                         FilterMessage (env);
68
69                         _transport.Send (env, _destination);
70                 }
71
72                 [MonoTODO]
73                 public IAsyncResult BeginSend (SoapEnvelope env, AsyncCallback callback, object state)
74                 {
75                         throw new NotImplementedException ();
76                 }
77
78                 [MonoTODO]
79                 public void EndSend (IAsyncResult result)
80                 {
81                         throw new NotImplementedException ();
82                 }
83
84                 public ISoapTransport Transport {
85                         get { return _transport; }
86                 }
87
88                 public EndpointReference Destination {
89                         get { return _destination; }
90                         set {
91                                 if(value == null || value.Address == null || value.Address.Value == null) {
92                                         throw new ArgumentNullException ("destination");
93                                 }
94                                 ISoapTransport trans = WebServicesConfiguration.MessagingConfiguration.GetTransport (value.Address.Value.Scheme);
95                                 if(trans == null) {
96                                         throw new ArgumentException ("Transport " + value.Address.Value.Scheme + " is not supported");
97                                 }
98                                 _destination = value;
99                                 _transport = trans;
100                         }
101                 }
102         }
103 }