2 // System.Web.Services.Protocols.SoapHttpClientProtocol.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
7 // Copyright (C) Tim Coleman, 2002
\r
13 using System.Reflection;
\r
14 using System.Web.Services;
\r
15 using System.Diagnostics;
\r
17 namespace System.Web.Services.Protocols {
\r
18 public class SoapHttpClientProtocol : HttpWebClientProtocol {
\r
20 #region Constructors
\r
22 public SoapHttpClientProtocol ()
\r
26 #endregion // Constructors
\r
31 protected IAsyncResult BeginInvoke (string methodName, object[] parameters, AsyncCallback callback, object asyncState)
\r
33 throw new NotImplementedException ();
\r
37 public void Discover ()
\r
39 throw new NotImplementedException ();
\r
43 protected object[] EndInvoke (IAsyncResult asyncResult)
\r
45 throw new NotImplementedException ();
\r
48 protected override WebRequest GetWebRequest (Uri uri)
\r
50 return WebRequest.Create (uri);
\r
54 // The `method_name' should be the name of our invoker, this is only used
\r
55 // for sanity checks, nothing else
\r
57 MethodInfo GetCallerMethod (string method_name)
\r
59 StackFrame stack_frame = new StackFrame (5, false);
\r
60 MethodInfo mi = (MethodInfo) stack_frame.GetMethod ();
\r
63 // A few sanity checks, just in case the code moves around later
\r
65 if (!mi.DeclaringType.IsSubclassOf (typeof (System.Web.Services.Protocols.SoapHttpClientProtocol)))
\r
66 throw new Exception ("We are pointing to the wrong method (T=" + mi.DeclaringType + ")");
\r
68 if (mi.DeclaringType == typeof (System.Web.Services.Protocols.SoapHttpClientProtocol))
\r
69 throw new Exception ("We are pointing to the wrong method (we are pointing to our Invoke)");
\r
71 if (mi.Name != method_name)
\r
72 throw new Exception ("The method we point to is: " + mi.Name);
\r
77 SoapClientMessage CreateMessage (string method_name, object [] parameters)
\r
79 MethodInfo mi = GetCallerMethod (method_name);
\r
80 object [] attributes = mi.GetCustomAttributes (typeof (System.Web.Services.Protocols.SoapDocumentMethodAttribute), false);
\r
81 SoapDocumentMethodAttribute sma = (SoapDocumentMethodAttribute) attributes [0];
\r
83 Console.WriteLine ("SMAA: " + sma.Action);
\r
84 Console.WriteLine ("Binding: " + sma.Binding);
\r
85 Console.WriteLine ("OneWay: " + sma.OneWay);
\r
86 Console.WriteLine ("PStyle: " + sma.ParameterStyle);
\r
87 Console.WriteLine ("REN: " + sma.RequestElementName);
\r
88 Console.WriteLine ("REN: " + sma.RequestElementName);
\r
90 SoapClientMessage message = new SoapClientMessage (
\r
91 this, sma, new LogicalMethodInfo (mi), sma.OneWay, Url);
\r
96 void SendMessage (WebRequest request, SoapClientMessage message)
\r
101 protected object[] Invoke (string method_name, object[] parameters)
\r
103 SoapClientMessage message = CreateMessage (method_name, parameters);
\r
104 WebRequest request = GetWebRequest (uri);
\r
105 Stream s = request.GetRequestStream ();
\r
108 SendMessage (request, message);
\r
116 #endregion // Methods
\r