Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels / SoapServerFormatterSink.cs
index 166b93d35dc74aac6678913634f67fa4f67467b9..d818bca48c7d190ac2309ed9459ba150728e93dc 100644 (file)
@@ -6,27 +6,27 @@
 //\r
 // 2002 (C) Copyright, Ximian, Inc.\r
 //\r
-
-//
-// 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.
-//
+\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
 \r
 using System.Collections;\r
 using System.IO;\r
@@ -86,7 +86,6 @@ namespace System.Runtime.Remoting.Channels {
                        }\r
                }\r
 \r
-#if NET_1_1\r
                [ComVisible(false)]\r
                public TypeFilterLevel TypeFilterLevel\r
                {\r
@@ -98,7 +97,6 @@ namespace System.Runtime.Remoting.Channels {
                                _soapCore = new SoapCore (this, props, SoapServerFormatterSinkProvider.AllowedProperties);\r
                        }\r
                }\r
-#endif\r
 \r
                public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,\r
                                                  IMessage msg, ITransportHeaders headers, Stream stream)\r
@@ -130,11 +128,36 @@ namespace System.Runtime.Remoting.Channels {
                                                        IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,\r
                                                        out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)\r
                {\r
+                       // Check whether the request was already processed by another\r
+                       // formatter sink and pass the request to the next sink if so.\r
+                       if (requestMsg != null)\r
+                               return next_sink.ProcessMessage (sinkStack,\r
+                                                                requestMsg,\r
+                                                                requestHeaders,\r
+                                                                requestStream,\r
+                                                                out responseMsg,\r
+                                                                out responseHeaders,\r
+                                                                out responseStream);\r
+\r
+                       // Check whether the request is suitable for this formatter\r
+                       // and pass the request to the next sink if not.\r
+                       // Note that a null content-type is handled as suitable,\r
+                       // otherwise no other sink will be able to handle the request.\r
+                       string contentType = requestHeaders["Content-Type"] as string;\r
+                       if (contentType == null || !contentType.StartsWith ("text/xml") || requestHeaders["SOAPAction"] == null) {\r
+                               return next_sink.ProcessMessage (sinkStack,\r
+                                       requestMsg,\r
+                                       requestHeaders,\r
+                                       requestStream,\r
+                                       out responseMsg,\r
+                                       out responseHeaders,\r
+                                       out responseStream);\r
+                       }\r
+\r
                        responseMsg = null;\r
                        responseHeaders = null;\r
                        responseStream = null;\r
 \r
-                       Exception exception;\r
                        ServerProcessing sp;\r
                        SoapMessageFormatter soapMsgFormatter = new SoapMessageFormatter();\r
                        sinkStack.Push(this, soapMsgFormatter);\r
@@ -150,7 +173,6 @@ namespace System.Runtime.Remoting.Channels {
                                SoapFormatter fm = _soapCore.GetSafeDeserializer ();\r
                                SoapMessage soapMessage = soapMsgFormatter.CreateSoapMessage (true);\r
                                fm.TopObject = soapMessage;\r
-                               requestStream.Position = 0;\r
                                fm.Deserialize(requestStream);\r
 \r
                                requestMsg = soapMsgFormatter.BuildMethodCallFromSoapMessage(soapMessage, uri);\r
@@ -163,6 +185,7 @@ namespace System.Runtime.Remoting.Channels {
                                                object rtnMessageObject = soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage) responseMsg, out responseHeaders);\r
                                                responseStream = new MemoryStream();\r
                                                _soapCore.Serializer.Serialize(responseStream, rtnMessageObject);\r
+                                               responseStream.Position = 0;\r
                                        }\r
                                }\r
                        }\r
@@ -172,6 +195,7 @@ namespace System.Runtime.Remoting.Channels {
                                object rtnMessageObject = soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage) responseMsg, out responseHeaders);\r
                                responseStream = new MemoryStream();\r
                                _soapCore.Serializer.Serialize(responseStream, rtnMessageObject);\r
+                               responseStream.Position = 0;\r
                                sp = ServerProcessing.Complete;\r
                        }\r
 \r