Browse Source

* SoapHttpClientProtocolTest.cs: Added test for bug #79988.
* SocketResponder.cs: Utility class for emulating Web Service backend.
* System.Web.Services_test.dll.sources: added SocketResponder.cs and
SoapHttpClientProtocolTest.cs.

svn path=/trunk/mcs/; revision=71044

Gert Driesen 19 years ago
parent
commit
da0f3b2ced

+ 5 - 0
mcs/class/System.Web.Services/ChangeLog

@@ -1,3 +1,8 @@
+2007-01-15  Gert Driesen  <[email protected]>
+
+	* System.Web.Services_test.dll.sources: added SocketResponder.cs and
+	SoapHttpClientProtocolTest.cs.
+
 2006-12-15  Atsushi Enomoto  <[email protected]>
 
 	* System.Web.Services_test.dll.sources :

+ 2 - 0
mcs/class/System.Web.Services/System.Web.Services_test.dll.sources

@@ -26,4 +26,6 @@ System.Web.Services.Description/SoapBodyBindingTest.cs
 System.Web.Services.Description/SoapOperationBindingTest.cs
 System.Web.Services.Description/WebReferenceTest.cs
 System.Web.Services.Description/WebReferenceOptionsTest.cs
+System.Web.Services.Protocols/SoapHttpClientProtocolTest.cs
+System.Web.Services.Protocols/SocketResponder.cs
 System.Web.Services.Protocols/WebClientProtocolTest.cs

+ 4 - 0
mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/ChangeLog

@@ -0,0 +1,4 @@
+2007-01-15  Gert Driesen  <[email protected]>
+
+	* SoapHttpClientProtocolTest.cs: Added test for bug #79988.
+	* SocketResponder.cs: Utility class for emulating Web Service backend.

+ 106 - 0
mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/SoapHttpClientProtocolTest.cs

@@ -0,0 +1,106 @@
+// 
+// System.Web.Services.Protocols.SoapHttpClientProtocolTest.cs
+//
+// Author:
+//   Gert Driesen <[email protected]>
+//
+// (C) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Net;
+using System.Web.Services;
+using System.Web.Services.Description;
+using System.Web.Services.Protocols;
+using System.Xml.Serialization;
+
+using NUnit.Framework;
+
+namespace System.Web.Services.Protocols
+{
+	[TestFixture]
+	public class SoapHttpClientProtocolTest
+	{
+		[Test] // bug #79988
+		public void OutParametersTest ()
+		{
+			IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
+			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (Response_OutParametersTest))) {
+				sr.Start ();
+
+				FooService service = new FooService ();
+				service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
+
+				int a;
+				bool b;
+				Elem [] e = service.Req ("x", out a, out b);
+				Assert.IsNull (e, "#A1");
+				Assert.AreEqual (0, a, "#A2");
+				Assert.IsFalse (b, "#A3");
+			}
+		}
+
+		static string Response_OutParametersTest ()
+		{
+			return "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+				"<soap:Body>" +
+				"<ReqResponse2 xmlns=\"urn:foo\">" +
+				"<Hits>ERERE</Hits>" +
+				"</ReqResponse2>" +
+				"</soap:Body>" +
+				"</soap:Envelope>";
+		}
+
+		[WebServiceBindingAttribute (Name = "Foo", Namespace = "urn:foo")]
+		public class FooService : SoapHttpClientProtocol
+		{
+			[SoapDocumentMethodAttribute ("", RequestElementName = "Req", RequestNamespace = "urn:foo", ResponseNamespace = "urn:foo", Use = SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+			[return: XmlElementAttribute ("Hits")]
+			public Elem [] Req ([XmlAttributeAttribute ()] string arg, [XmlAttributeAttribute ()] out int status, [XmlAttributeAttribute ()] [XmlIgnoreAttribute ()] out bool statusSpecified)
+			{
+				object [] results = this.Invoke ("Req", new object [] { arg });
+				status = ((int) (results [1]));
+				statusSpecified = ((bool) (results [2]));
+				return ((Elem []) (results [0]));
+			}
+		}
+
+		[SerializableAttribute ()]
+		public class Elem
+		{
+			private string attrField;
+
+			[XmlAttributeAttribute ()]
+			public string attr
+			{
+				get
+				{
+					return this.attrField;
+				}
+				set
+				{
+					this.attrField = value;
+				}
+			}
+		}
+	}
+}

+ 77 - 0
mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/SocketResponder.cs

@@ -0,0 +1,77 @@
+using System;
+using System.Globalization;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+
+public delegate string SocketRequestHandler ();
+
+public class SocketResponder : IDisposable
+{
+	private TcpListener tcpListener;
+	private readonly IPEndPoint _localEndPoint;
+	private Thread listenThread;
+	private SocketRequestHandler _requestHandler;
+
+	public SocketResponder (IPEndPoint localEP, SocketRequestHandler requestHandler)
+	{
+		_localEndPoint = localEP;
+		_requestHandler = requestHandler;
+	}
+
+	public IPEndPoint LocalEndPoint
+	{
+		get { return _localEndPoint; }
+	}
+
+	public void Dispose ()
+	{
+		Stop ();
+	}
+
+	public void Start ()
+	{
+		tcpListener = new TcpListener (LocalEndPoint);
+		tcpListener.Start ();
+		listenThread = new Thread (new ThreadStart (Listen));
+		listenThread.Start ();
+	}
+
+	public void Stop ()
+	{
+		if (tcpListener != null)
+			tcpListener.Stop ();
+
+		try {
+			if (listenThread != null && listenThread.ThreadState == ThreadState.Running) {
+				listenThread.Abort ();
+			}
+		} catch {
+		}
+	}
+
+	private void Listen ()
+	{
+		Socket socket = tcpListener.AcceptSocket ();
+
+		string content = _requestHandler ();
+
+		MemoryStream outputStream = new MemoryStream ();
+		StreamWriter sw = new StreamWriter (outputStream, Encoding.UTF8);
+		sw.WriteLine ("HTTP/1.1 200 OK");
+		sw.WriteLine ("Content-Type: text/xml");
+		sw.WriteLine ("Content-Length: " + content.Length.ToString (CultureInfo.InvariantCulture));
+		sw.WriteLine ();
+		sw.Write (content);
+		sw.Flush ();
+
+		outputStream.Position = 0;
+
+		using (StreamReader sr = new StreamReader (outputStream)) {
+			byte [] buffer = Encoding.UTF8.GetBytes (sr.ReadToEnd ());
+			socket.Send (buffer);
+		}
+	}
+}