[Mono-bugs] [Bug 51281][Nor] New - SoapHttpClientProtocol - InvalidCastException when using custom WebResponse (works on MS.NET 1.1)

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 21 Nov 2003 17:47:08 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by rsbarro@metaverse.cc.

http://bugzilla.ximian.com/show_bug.cgi?id=51281

--- shadow/51281	2003-11-21 17:47:07.000000000 -0500
+++ shadow/51281.tmp.6715	2003-11-21 17:47:08.000000000 -0500
@@ -0,0 +1,216 @@
+Bug#: 51281
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: Gentoo
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System.Web
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: rsbarro@metaverse.cc               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Summary: SoapHttpClientProtocol - InvalidCastException when using custom WebResponse (works on MS.NET 1.1)
+
+Description of Problem:
+The problem I am having lies within the
+System.Web.Services.Protocols.SoapHttpClientProtocol class, in the
+ReceiveResponse() method.  What I'm doing is unconventional but the code
+I'm testing with works perfect on the MS .NET 1.1 Framework.
+
+Basically, I'm writing a component that simplifies and caches the results
+of a web service call.  The unconventional part is that the web service
+returns a SOAP message and other binary data inside a Multipart MIME
+message.  To make this work in .NET, I hijack the response stream, parse
+the MIME message, and then return a response stream containing the expected
+SOAP message (contained in the first MIME attachment).  The net effect is
+something very similar to using WSE for sending and receiving attachments.
+
+When executing my test code on mono/Linux (Gentoo), I get the following
+exception:
+System.InvalidCastException: Cannot cast from source type to destination type
+in <0x00080>
+System.Web.Services.Protocols.SoapHttpClientProtocol:ReceiveResponse
+
+I'm thinking that the InvalidCastException has something to do with the
+fact that I'm sending a MemoryStream (via my MimeWebResponse class included
+below) to ReceiveRespose, instead of the System.Net.ConnectStream that is
+normally handled by ReceiveResponse.  
+
+I am hoping to get in touch with one of the component owners regarding this
+issue.  I would be happy to come up with a test case, but since I think it
+may take a bit of time (since it would have to include writing a web
+service as well) I'd like to discuss it first.
+
+Thanks,
+Rich
+
+Additional Information:
+
+Stack trace:
+Exception logged at: 11/21/2003 17:26:14
+Metaverse.Web.Services.Exceptions.ExecuteContentQueriesException: An error
+occurred while attempting to execute content queries against the Cache or
+Content Server. ---> System.InvalidCastException: Cannot cast from source
+type to destination type
+in <0x00080>
+System.Web.Services.Protocols.SoapHttpClientProtocol:ReceiveResponse
+(System.Net.WebResponse,System.Web.Services.Protocols.SoapClientMessage,System.Web.Services.Protocols.SoapExtension[])
+in <0x0007d> (wrapper remoting-invoke-with-check)
+System.Web.Services.Protocols.SoapHttpClientProtocol:ReceiveResponse
+(System.Net.WebResponse,System.Web.Services.Protocols.SoapClientMessage,System.Web.Services.Protocols.SoapExtension[])
+in <0x00225> System.Web.Services.Protocols.SoapHttpClientProtocol:Invoke
+(string,object[])
+in <0x00068>
+Metaverse.Web.Services.Protocols.SoapMimeHttpClientProtocol:Invoke
+(string,object[])
+in <0x0006b> (wrapper remoting-invoke-with-check)
+Metaverse.Web.Services.Protocols.SoapMimeHttpClientProtocol:Invoke
+(string,object[])
+in <0x000b7>
+Metaverse.Web.Services.ContentServer200.CQLService:ExecuteCQLContent
+(Metaverse.Web.Services.ContentServer200.CQLRequest[])
+in <0x00058> (wrapper remoting-invoke-with-check)
+Metaverse.Web.Services.ContentServer200.CQLService:ExecuteCQLContent
+(Metaverse.Web.Services.ContentServer200.CQLRequest[])
+in <0x003a5> Metaverse.Web.Services.AgentObjects.ContentCollection:Execute ()
+--- End of inner exception stack trace ---
+
+My MimeWebResponse class (inherits from System.Net.WebResponse): 
+
+using System;
+using System.IO;
+using System.Net;
+
+namespace Metaverse.Web.Services.Protocols
+{
+	/// <summary>
+	/// Represents the response from a multipart MIME enabled web service.
+	/// </summary>
+	public class MimeWebResponse : System.Net.WebResponse
+	{
+		#region Constructors
+		/// <summary>
+		/// Initializes a new instance of the MimeWebResponse class.
+		/// </summary>
+		internal MimeWebResponse()
+		{
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the MimeWebResponse class from an
+existing WebResponse.
+		/// </summary>
+		/// <param name="response">An exisitng System.Net.WebResponse
+instance.</param>
+		internal MimeWebResponse(System.Net.WebResponse response)
+		{
+			this.ContentLength = response.ContentLength;
+			this.ContentType = response.ContentType;
+			this.SetHeaders(response.Headers);
+			this.SetResponseStream(response.GetResponseStream());
+			this.SetResponseUri(response.ResponseUri);
+		}
+		#endregion
+		#region Private Variables
+		private long _contentLength;
+		private string _contentType;
+		private WebHeaderCollection _headers;
+		private Stream _responseStream;
+		private Uri _responseUri;
+		#endregion
+		#region Public Properties
+        /// <summary>
+        /// Gets or sets the Content Length of this response.
+        /// </summary>
+		public override long ContentLength
+		{
+			get { return _contentLength; }
+			set { _contentLength = value; }
+		}
+
+		/// <summary>
+		/// Gets or sets the Content Type of this response.
+		/// </summary>
+		public override string ContentType
+		{
+			get { return _contentType; }
+			set { _contentType = value; }
+		}
+
+		/// <summary>
+		/// Gets the Headers collection for this response.
+		/// </summary>
+		public override WebHeaderCollection Headers
+		{
+			get { return _headers; }
+		}
+
+		/// <summary>
+		/// Gets the ResponseUri for this response.
+		/// </summary>
+		public override Uri ResponseUri
+		{
+			get { return _responseUri; }
+		}
+		#endregion
+		#region Public Methods
+		/// <summary>
+		/// Sets the Headers collection for this instance.
+		/// </summary>
+		public void SetHeaders(WebHeaderCollection headers)
+		{
+			_headers = headers;
+		}
+
+		/// <summary>
+		/// Sets the response stream for this instance.
+		/// </summary>
+		/// <param name="responseStream"></param>
+		public void SetResponseStream(Stream responseStream)
+		{
+			_responseStream = responseStream;
+		}
+
+		/// <summary>
+		/// Gets the ResponseStream for this instance.
+		/// </summary>
+		public override Stream GetResponseStream()
+		{
+			return _responseStream;
+		}
+
+		/// <summary>
+		/// Sets the ResponseUri for this instance.
+		/// </summary>
+		public void SetResponseUri(Uri responseUri)
+		{
+			_responseUri = responseUri;
+		}
+
+		/// <summary>
+		/// Parses a value from the supplied string.
+		/// </summary>
+		public string ParseValues(string valueString, string parameter, string
+defaultValue)
+		{
+			try
+			{
+				int start = valueString.IndexOf(string.Concat(parameter, "=")) +
+(parameter.Length + 1);
+				int end = valueString.IndexOf(";", start);
+				if(start > 0 && end < 0)
+					end = valueString.Length;
+				return valueString.Substring(start, end - start);
+			}
+			catch
+			{
+				return defaultValue;
+			}
+		}
+		#endregion
+	}
+}