Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,169 @@
//
// System.Runtime.Remoting.Channels.BinaryClientFormatterSink.cs
//
// Author: Rodrigo Moya (rodrigo@ximian.com)
// Dietmar Maurer (dietmar@ximian.com)
// Lluis Sanchez Gual (lluis@ideary.com)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
using System.IO;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace System.Runtime.Remoting.Channels
{
public class BinaryClientFormatterSink : IClientFormatterSink,
IMessageSink, IClientChannelSink, IChannelSinkBase
{
BinaryCore _binaryCore = BinaryCore.DefaultInstance;
IClientChannelSink _nextInChain;
public BinaryClientFormatterSink (IClientChannelSink nextSink)
{
_nextInChain = nextSink;
}
internal BinaryCore BinaryCore
{
get { return _binaryCore; }
set { _binaryCore = value; }
}
public IClientChannelSink NextChannelSink
{
get {
return _nextInChain;
}
}
public IMessageSink NextSink
{
get {
// This is the last sink in the IMessageSink sink chain
return null;
}
}
public IDictionary Properties
{
get {
return null;
}
}
public void AsyncProcessRequest (IClientChannelSinkStack sinkStack,
IMessage msg,
ITransportHeaders headers,
Stream stream)
{
// never called because the formatter sink is
// always the first in the chain
throw new NotSupportedException("BinaryClientFormatterSink must be the first sink in the IClientChannelSink chain");
}
public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack,
object state,
ITransportHeaders headers,
Stream stream)
{
IMessage replyMessage = (IMessage)_binaryCore.Deserializer.DeserializeMethodResponse (stream, null, (IMethodCallMessage)state);
sinkStack.DispatchReplyMessage (replyMessage);
}
public Stream GetRequestStream (IMessage msg,
ITransportHeaders headers)
{
// never called
throw new NotSupportedException ();
}
public void ProcessMessage (IMessage msg,
ITransportHeaders requestHeaders,
Stream requestStream,
out ITransportHeaders responseHeaders,
out Stream responseStream)
{
// never called because the formatter sink is
// always the first in the chain
throw new NotSupportedException ();
}
public IMessageCtrl AsyncProcessMessage (IMessage msg,
IMessageSink replySink)
{
ITransportHeaders transportHeaders = new TransportHeaders();
transportHeaders[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri;
transportHeaders["Content-Type"] = "application/octet-stream";
Stream stream = _nextInChain.GetRequestStream(msg, transportHeaders);
if (stream == null) stream = new MemoryStream ();
_binaryCore.Serializer.Serialize (stream, msg, null);
if (stream is MemoryStream) stream.Position = 0;
ClientChannelSinkStack stack = new ClientChannelSinkStack(replySink);
stack.Push (this, msg);
_nextInChain.AsyncProcessRequest (stack, msg, transportHeaders, stream);
// FIXME: No idea about how to implement IMessageCtrl
return null;
}
public IMessage SyncProcessMessage (IMessage msg)
{
try {
ITransportHeaders call_headers = new TransportHeaders();
call_headers[CommonTransportKeys.RequestUri] = ((IMethodCallMessage)msg).Uri;
call_headers["Content-Type"] = "application/octet-stream";
Stream call_stream = _nextInChain.GetRequestStream(msg, call_headers);
if (call_stream == null) call_stream = new MemoryStream ();
// Serialize msg to the stream
_binaryCore.Serializer.Serialize (call_stream, msg, null);
if (call_stream is MemoryStream) call_stream.Position = 0;
Stream response_stream;
ITransportHeaders response_headers;
_nextInChain.ProcessMessage (msg, call_headers, call_stream, out response_headers,
out response_stream);
// Deserialize response_stream
return (IMessage) _binaryCore.Deserializer.DeserializeMethodResponse (response_stream, null, (IMethodCallMessage)msg);
} catch (Exception e) {
return new ReturnMessage (e, (IMethodCallMessage)msg);
}
}
}
}

View File

@@ -0,0 +1,81 @@
//
// System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider.cs
//
// Author: Rodrigo Moya (rodrigo@ximian.com)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
namespace System.Runtime.Remoting.Channels
{
public class BinaryClientFormatterSinkProvider :
IClientFormatterSinkProvider, IClientChannelSinkProvider
{
IClientChannelSinkProvider next = null;
BinaryCore _binaryCore;
static string[] allowedProperties = new string [] { "includeVersions", "strictBinding", "typeFilterLevel" };
public BinaryClientFormatterSinkProvider ()
{
_binaryCore = BinaryCore.DefaultInstance;
}
public BinaryClientFormatterSinkProvider (IDictionary properties,
ICollection providerData)
{
_binaryCore = new BinaryCore (this, properties, allowedProperties);
}
public IClientChannelSinkProvider Next
{
get {
return next;
}
set {
next = value;
}
}
public IClientChannelSink CreateSink (IChannelSender channel,
string url,
object remoteChannelData)
{
IClientChannelSink next_sink = null;
BinaryClientFormatterSink result;
if (next != null)
next_sink = next.CreateSink (channel, url, remoteChannelData);
result = new BinaryClientFormatterSink (next_sink);
result.BinaryCore = _binaryCore;
return result;
}
}
}

View File

@@ -0,0 +1,146 @@
//
// System.Runtime.Remoting.Channels.BinaryCore.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Novell, Inc.
//
//
// 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.Collections;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
namespace System.Runtime.Remoting.Channels
{
internal class BinaryCore
{
BinaryFormatter _serializationFormatter;
BinaryFormatter _deserializationFormatter;
bool _includeVersions = true;
bool _strictBinding = false;
IDictionary _properties;
TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
public static BinaryCore DefaultInstance = new BinaryCore ();
public BinaryCore (object owner, IDictionary properties, string[] allowedProperties)
{
_properties = properties;
if (_properties == null)
{
_properties = new Hashtable(10);
}
foreach(DictionaryEntry property in properties)
{
string key = (string) property.Key;
if (Array.IndexOf (allowedProperties, key) == -1)
throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
switch (key)
{
case "includeVersions":
_includeVersions = Convert.ToBoolean (property.Value);
break;
case "strictBinding":
_strictBinding = Convert.ToBoolean (property.Value);
break;
case "typeFilterLevel":
if (property.Value is TypeFilterLevel)
_filterLevel = (TypeFilterLevel) property.Value;
else {
string s = (string) property.Value;
_filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
}
break;
}
}
Init ();
}
public BinaryCore ()
{
_properties = new Hashtable ();
Init ();
}
public void Init ()
{
RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
#if !TARGET_JVM
_serializationFormatter = new BinaryFormatter (surrogateSelector, context);
_deserializationFormatter = new BinaryFormatter (null, context);
#else
_serializationFormatter = (BinaryFormatter) vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (surrogateSelector, context, false);
_deserializationFormatter = (BinaryFormatter) vmw.@internal.remoting.BinaryFormatterUtils.CreateBinaryFormatter (null, context, false);
#endif
_serializationFormatter.FilterLevel = _filterLevel;
_deserializationFormatter.FilterLevel = _filterLevel;
if (!_includeVersions)
{
_serializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
_deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
}
if (!_strictBinding)
{
_serializationFormatter.Binder = ChannelCore.SimpleBinder;
_deserializationFormatter.Binder = ChannelCore.SimpleBinder;
}
}
public BinaryFormatter Serializer
{
get { return _serializationFormatter; }
}
public BinaryFormatter Deserializer
{
get { return _deserializationFormatter; }
}
public IDictionary Properties
{
get { return _properties; }
}
public TypeFilterLevel TypeFilterLevel
{
get { return _filterLevel; }
}
}
}

View File

@@ -0,0 +1,214 @@
//
// System.Runtime.Remoting.Channels.BinaryServerFormatterSink.cs
//
// Author: Duncan Mak (duncan@ximian.com)
// Lluis Sanchez Gual (lluis@ideary.com)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
using System.IO;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting.Channels {
public class BinaryServerFormatterSink : IServerChannelSink, IChannelSinkBase
{
[Serializable]
public enum Protocol
{
Http = 0,
Other = 1,
}
BinaryCore _binaryCore = BinaryCore.DefaultInstance;
IServerChannelSink next_sink;
Protocol protocol;
IChannelReceiver receiver;
public BinaryServerFormatterSink (BinaryServerFormatterSink.Protocol protocol,
IServerChannelSink nextSink,
IChannelReceiver receiver)
{
this.protocol = protocol;
this.next_sink = nextSink;
this.receiver = receiver;
}
internal BinaryCore BinaryCore
{
get { return _binaryCore; }
set { _binaryCore = value; }
}
public IServerChannelSink NextChannelSink {
get {
return next_sink;
}
}
public IDictionary Properties {
get {
return null;
}
}
[ComVisible(false)]
public TypeFilterLevel TypeFilterLevel
{
get { return _binaryCore.TypeFilterLevel; }
set
{
IDictionary props = (IDictionary) ((ICloneable)_binaryCore.Properties).Clone ();
props ["typeFilterLevel"] = value;
_binaryCore = new BinaryCore (this, props, BinaryServerFormatterSinkProvider.AllowedProperties);
}
}
public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
IMessage msg, ITransportHeaders headers, Stream stream)
{
ITransportHeaders responseHeaders = new TransportHeaders();
if (sinkStack != null) stream = sinkStack.GetResponseStream (msg, responseHeaders);
if (stream == null) stream = new MemoryStream();
_binaryCore.Serializer.Serialize (stream, msg, null);
if (stream is MemoryStream) stream.Position = 0;
sinkStack.AsyncProcessResponse (msg, responseHeaders, stream);
}
public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack, object state,
IMessage msg, ITransportHeaders headers)
{
return null;
}
public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
{
// Check whether the request was already processed by another
// formatter sink and pass the request to the next sink if so.
if (requestMsg != null)
return next_sink.ProcessMessage (sinkStack,
requestMsg,
requestHeaders,
requestStream,
out responseMsg,
out responseHeaders,
out responseStream);
// Check whether the request is suitable for this formatter
// and pass the request to the next sink if not.
// Note that a null content-type is handled as suitable,
// otherwise no other sink will be able to handle the request.
string contentType = requestHeaders["Content-Type"] as string;
if (contentType != null && contentType != "application/octet-stream") {
try {
return next_sink.ProcessMessage (sinkStack,
requestMsg,
requestHeaders,
requestStream,
out responseMsg,
out responseHeaders,
out responseStream);
} catch {
// Let this formatter handle the exception.
}
}
sinkStack.Push (this, null);
ServerProcessing res;
try
{
string url = (string)requestHeaders[CommonTransportKeys.RequestUri];
string uri;
receiver.Parse (url, out uri);
if (uri == null) uri = url;
MethodCallHeaderHandler mhh = new MethodCallHeaderHandler(uri);
requestMsg = (IMessage) _binaryCore.Deserializer.Deserialize (requestStream, new HeaderHandler(mhh.HandleHeaders));
res = next_sink.ProcessMessage (sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
}
catch (Exception ex)
{
responseMsg = new ReturnMessage (ex, (IMethodCallMessage)requestMsg);
res = ServerProcessing.Complete;
responseHeaders = null;
responseStream = null;
}
if (res == ServerProcessing.Complete)
{
for (int n=0; n<3; n++) {
responseStream = null;
responseHeaders = new TransportHeaders();
if (sinkStack != null) responseStream = sinkStack.GetResponseStream (responseMsg, responseHeaders);
if (responseStream == null) responseStream = new MemoryStream();
try {
_binaryCore.Serializer.Serialize (responseStream, responseMsg);
break;
} catch (Exception ex) {
if (n == 2) throw ex;
else responseMsg = new ReturnMessage (ex, (IMethodCallMessage)requestMsg);
}
}
if (responseStream is MemoryStream) responseStream.Position = 0;
sinkStack.Pop (this);
}
return res;
}
}
internal class MethodCallHeaderHandler
{
string _uri;
public MethodCallHeaderHandler (string uri)
{
_uri = uri;
}
public object HandleHeaders (Header[] headers)
{
return _uri;
}
}
}

View File

@@ -0,0 +1,99 @@
//
// System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider.cs
//
// Author: Rodrigo Moya (rodrigo@ximian.com)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
using System.Runtime.Serialization.Formatters;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting.Channels
{
public class BinaryServerFormatterSinkProvider :
IServerFormatterSinkProvider, IServerChannelSinkProvider
{
IServerChannelSinkProvider next = null;
BinaryCore _binaryCore;
internal static string[] AllowedProperties = new string [] { "includeVersions", "strictBinding", "typeFilterLevel" };
public BinaryServerFormatterSinkProvider ()
{
_binaryCore = BinaryCore.DefaultInstance;
}
public BinaryServerFormatterSinkProvider (IDictionary properties,
ICollection providerData)
{
_binaryCore = new BinaryCore (this, properties, AllowedProperties);
}
public IServerChannelSinkProvider Next
{
get {
return next;
}
set {
next = value;
}
}
[ComVisible(false)]
public TypeFilterLevel TypeFilterLevel
{
get { return _binaryCore.TypeFilterLevel; }
set
{
IDictionary props = (IDictionary) ((ICloneable)_binaryCore.Properties).Clone ();
props ["typeFilterLevel"] = value;
_binaryCore = new BinaryCore (this, props, AllowedProperties);
}
}
public IServerChannelSink CreateSink (IChannelReceiver channel)
{
IServerChannelSink next_sink = null;
BinaryServerFormatterSink result;
if (next != null)
next_sink = next.CreateSink (channel);
result = new BinaryServerFormatterSink (BinaryServerFormatterSink.Protocol.Other,
next_sink, channel);
result.BinaryCore = _binaryCore;
return result;
}
public void GetChannelData (IChannelDataStore channelData)
{
// Nothing to add here
}
}
}

View File

@@ -0,0 +1,234 @@
2008-09-23 Michael Hutchinson <mhutchinson@novell.com>
* SoapServerFormatterSink.cs: Do not try to parse text/xml code
unless there is a SOAPAction. Set position on outgoing streams to
zero, so they can be properly parsed in the general infrastructure.
Do not try to seek on incoming streams.
2008-08-09 Gert Driesen <drieseng@users.sourceforge.net>
* BinaryServerFormatterSink.cs: Fixed argument name to match MS.
* SoapClientFormatterSink.cs: Fixed argument name to match MS. Code
formatting.
* SocketCachePolicy.cs: Added.
2007-05-10 Jonathan Chambers <joncham@gmail.com>
* BinaryClientFormatterSinkProvider.cs: Allow typeFilterLevel property
if NET_1_1 or greater; matches code already in BinaryCore.
2007-05-07 Robert Jordan <robertj@gmx.net>
* SoapMessageFormatter.cs (BuildMethodCallFromSoapMessage):
Validate DecodeXmlNamespaceForClrTypeNamespace's result.
Don't use RemotingServices.GetServerTypeForUri's result to
lookup the method from, because it returns the concrete server
type. We need the type that was used to make the call, which
we can compute from DecodeXmlNamespaceForClrTypeNamespace's output.
Fixes the last part of bug #77191.
2007-28-02 Lluis Sanchez Gual <lluis@novell.com>
* ChannelCore.cs: Added missing null check. LoadWithPartialName can
return null.
2006-12-18 Lluis Sanchez Gual <lluis@novell.com>
* SoapMessageFormatter.cs: FieldSetter and FieldGetter methods need
to be handled in a special way, since they are the only private
methods which can be called from a subclass.
2006-05-31 Gert Driesen <drieseng@users.sourceforge.net>
* SoapCore.cs: Set eol-style to native.
* SoapServerFormatterSinkProvider.cs: Fixed line endings. Set eol-style
to CRLF.
* ChannelCore.cs: Set eol-style to native.
* BinaryServerFormatterSink.cs: Set eol-style to native.
* SoapClientFormatterSinkProvider.cs: Fixed line endings. Set eol-style
to CRLF. Next and CreateSink should not be virtual.
* SoapMessageFormatter.cs: Set eol-style to CRLF.
* BinaryClientFormatterSink.cs: Fixed line endings. Set eol-style to
native.
* BinaryCore.cs: Set eol-style to native.
* BinaryServerFormatterSinkProvider.cs: Set eol-style to native.
* CommonTransportKeys.cs: Set eol-style to native.
* SoapServerFormatterSink.cs: Fixed line endings. Set eol-style to CRLF.
* RemotingThreadPool.cs: Fixed line endings. Set eol-style to native.
* BinaryClientFormatterSinkProvider.cs: Set eol-style to native.
* SoapClientFormatterSink.cs: Fixed line endings. Set eol-style to CRLF.
2006-03-05 Andrew Skiba <andrews@mainsoft.com>
* SoapMessageFormatter.cs: : exceptions propagating
incompatible with dotnet. Patch by roeie@mainsoft.com
2006-01-26 Svetlana Zholkovsky <svetlanaz@mainsoft.com>
* BinaryCore.cs: TARGET_JVM related changes
2005-12-05 Robert Jordan <robertj@gmx.net>
* BinaryServerFormatterSink.cs, SoapServerFormatterSink.cs:
Implemented formatter chaining. Fixes bug #74878.
* BinaryClientFormatterSink.cs: AsyncProcessMessage: Set the transport
headers.
2005-11-05 Robert Jordan <robertj@gmx.net>
* IAuthorizeRemotingConnection.cs: Added.
2005-11-06 Svetlana Zholkovsky <svetlanaz@mainsoft.com>
* SoapMessageFormatter.cs, RemotingThreadPool.cs: only TARGET_JVM changes
* Create new dictionary object for Properties during initialization:
- SoapCore.cs
- BinaryCore.cs
2005-05-18 Lluis Sanchez Gual <lluis@novell.com>
* BinaryServerFormatterSink.cs: Properly handle exceptions raised
during serialization. Fixes bug #74950.
2005-01-14 Lluis Sanchez Gual <lluis@novell.com>
* SoapMessageFormatter.cs, SoapServerFormatterSink.cs: Fixed warnings.
* RemotingThreadPool.cs: New thread pool for the tcp and http channels.
2004-07-26 Lluis Sanchez Gual <lluis@ximian.com>
* SoapMessageFormater.cs: In BuildSoapMessageFromMethodResponse, add the
return value to the SoapMessage even if it is null. This fixes bug #61837.
2004-07-06 Lluis Sanchez Gual <lluis@ximian.com>
* SoapMessageFormatter.cs: In BuildMethodCallFromSoapMessage, set get the
parameters from the SoapMessage by position, not by name, since names
may be different. This fixes bug #60427.
2004-06-16 Lluis Sanchez Gual <lluis@ximian.com>
* SoapServerFormatterSink.cs: Removed unneded method.
2004-06-10 Lluis Sanchez Gual <lluis@ximian.com>
* SoapMessageFormatter.cs: Don't add the signature to the headers list if
the method is not overloaded, and don't add the LogicalCallContext if
it has no info.
2004-05-26 Lluis Sanchez Gual <lluis@ximian.com>
* SoapMessageFormatter.cs: Include soap headers as properties when creating
the IMessage, and add IMessage properties as headers when creating the
SoapMessage. LogicalCallContext info will be passed as a header value.
2004-05-13 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryCore.cs, SoapCore.cs: Added Properties property.
* BinaryServerFormatterSink.cs, SoapServerFormatterSink.cs: Added missing
TypeFilterLevel property.
* BinaryServerFormatterSinkProvider.cs: Fixed setter for TypeFilterLevel.
* SoapServerFormatterSinkProvider.cs: Added missing TypeFilterLevel
property.
2004-05-11 Lluis Sanchez Gual <lluis@ximian.com>
* ChannelCore.cs: Use LoadWithPartialName when configuration information
is not present.
2004-04-30 Lluis Sanchez Gual <lluis@ximian.com>
* SoapClientFormatterSink.cs: The deserialized message can be actually a
SoapFault. Taken this into account.
* SoapMessageFormatter.cs: Added FormatFault method. In FormatResponse(),
the array of output parameters must also include placeholders for the
input parameters (set to null).
ParameterInfo.IsOut does not correspond to the "out" keyword in C#, but
to the OutAttribute applied to parameters. There can be input parameters
with the OutAttribute. Fixed this in a couple of places.
Added CreateSoapMessage method, which creates a SoapMessage including
the parameter types (only for responses, since for requests the target
method is not known).
* SoapServerFormatterSink.cs: Use soapMsgFormatter.CreateSoapMessage to
create the SoapMessage.
2004-02-27 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryClientFormatterSink.cs: Don't set the request uri here, this will
be done in the transport sink.
* BinaryCore.cs: Added TypeFilterLevel property.
* BinaryServerFormatterSinkProvider.cs: Added missing TypeFilterLevel property.
2003-12-15 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryServerFormatterSinkProvider.cs, SoapServerFormatterSinkProvider.cs:
Changed some ifdefs for allowedProperties field.
2003-12-11 Patrik Torstensson <p@rxc.se>
* SoapMessageFormater.cs: Use GetMethod with signature if possible, solves
AmbiguousMatchException for bug 51990.
2003-12-10 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryServerFormatterSinkProvider.cs: Removed TODO.
* CommonTransportKeys.cs: Added some internal transport keys.
2003-11-21 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryClientFormatterSinkProvider.cs, BinaryServerFormatterSinkProvider.cs,
BinaryCore.cs, BinaryServerFormatterSinkProvider.cs,
SoapClientFormatterSinkProvider.cs, SoapCore.cs,
SoapServerFormatterSinkProvider.cs.cs: Added support for TypeFilterLevel
property.
2003-11-17 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryClientFormatterSinkProvider.cs, BinaryServerFormatterSinkProvider.cs:
SoapClientFormatterSinkProvider.cs, SoapServerFormatterSinkProvider.cs: Small fix.
* SoapServerFormatterSink.cs: Small fix in AsyncProcessResponse.
* BinaryCore.cs, SoapCore.cs: throw an exception if an unknown property
is found.
2003-11-16 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryClientFormatterSink.cs, BinaryClientFormatterSinkProvider.cs,
BinaryServerFormatterSink.cs, BinaryServerFormatterSinkProvider.cs:
Moved formatter code to BinaryCore. This adds support for the properties
"includeVersion" and "strictBinding" to the binary formatter.
* BinaryCore.cs: New file. Contains some code used by the binary formatter sinks.
* SoapClientFormatterSink.cs, SoapClientFormatterSinkProvider.cs,
SoapServerFormatterSink.cs, SoapServerFormatterSinkProvider.cs
Moved formatter code to BinaryCore. This adds support for the properties
"includeVersion" and "strictBinding" to the soap formatter.
* SoapCore.cs: New file. Contains some code used by the soap formatter sinks.
* ChannelCore.cs: New file. Implements a simple type binder used by the
formatter sinks.
2003-11-12 Lluis Sanchez Gual <lluis@ximian.com>
* BinaryServerFormatterSink.cs: Removed fixme.
* BinaryServerFormatterSinkProvider.cs: Removed a NotImplementedException.
* SoapServerFormatterSinkProvider.cs: Removed some TODOs.
2003-09-25 Lluis Sanchez Gual <lluis@ximian.com>
* SoapMessageFormatter.cs: Consider parameters with Out flag when collectiong
out parameters.
2003-08-22 Lluis Sanchez Gual <lluis@ximian.com>
* SoapClientFormatterSink.cs: Fixed a some bugs to make async calls work.
* SoapMessageFormatter.cs: Fixed some problems with out and ref parameters.
* SoapServerFormatterSink.cs: Improved catching of exceptions.
2003-07-23 Lluis Sanchez Gual <lluis@ximian.com>
* SoapMessageFormatter.cs: ParameterInfo.Position is now zero-based.
Fixed methods that use it.
2003-07-09: Jean-Marc André <jean-marc.andre@polymtl.ca>
* SoapClientFormatterSink.cs, SoapClientFormatterSinkProvider.cs,
SoapServerFormatterSink.cs, SoapServerFormatterSinkProvider.cs,
SoapMessageFormatter.cs: Support for the soap serialization added to
the remoting infrastructure.

View File

@@ -0,0 +1,67 @@
//
// System.Runtime.Remoting.Channels.ChannelCore.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Novell, Inc.
//
//
// 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.Reflection;
using System.Runtime.Serialization;
namespace System.Runtime.Remoting.Channels
{
internal class ChannelCore
{
public static SerializationBinder SimpleBinder = new SimpleBinder();
}
internal class SimpleBinder: SerializationBinder
{
public override Type BindToType (String assemblyName, string typeName)
{
Assembly asm;
if (assemblyName.IndexOf (',') != -1)
{
// Try using the full name
try
{
asm = Assembly.Load (assemblyName);
Type t = asm.GetType (typeName);
if (t != null) return t;
}
catch {}
}
// Try using the simple name
asm = Assembly.LoadWithPartialName (assemblyName);
if (asm == null)
return null;
return asm.GetType (typeName, true);
}
}
}

View File

@@ -0,0 +1,53 @@
//
// System.Runtime.Remoting.Channels.CommonTransportKeys.cs
//
// Author: Rodrigo Moya (rodrigo@ximian.com)
// Lluis Sanchez Gual (lsg@ctv.es)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.
//
namespace System.Runtime.Remoting.Channels
{
public class CommonTransportKeys
{
public const string ConnectionId = "__ConnectionId";
public const string IPAddress = "__IPAddress";
public const string RequestUri = "__RequestUri";
internal const string RequestVerb = "__RequestVerb";
internal const string HttpVersion = "__HttpVersion";
internal const string ContentType = "Content-Type";
internal const string UserAgent = "User-Agent";
internal const string Host = "Host";
internal const string SoapAction = "SOAPAction";
internal const string HttpStatusCode = "__HttpStatusCode";
internal const string HttpReasonPhrase = "__HttpReasonPhrase";
public CommonTransportKeys ()
{
}
}
}

View File

@@ -0,0 +1,45 @@
//
// System.Runtime.Remoting.Channels.IAuthorizeRemotingConnection.cs
//
// Author: Robert Jordan (robertj@gmx.net)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
//
// 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.
//
#if NET_2_0
using System;
using System.Net;
using System.Security.Principal;
namespace System.Runtime.Remoting.Channels
{
public interface IAuthorizeRemotingConnection
{
bool IsConnectingEndPointAuthorized (EndPoint endPoint);
bool IsConnectingIdentityAuthorized (IIdentity identity);
}
}
#endif

View File

@@ -0,0 +1,182 @@
//
// System.Runtime.Remoting.Channels.RemotingThreadPool.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2005 (C) Copyright, Novell, Inc.
//
//
// 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.Collections;
using System.Threading;
namespace System.Runtime.Remoting.Channels
{
internal class RemotingThreadPool
{
const int ThreadLimit = 1000;
const int ThreadWaitTime = 20000; //ms
const int PoolGrowDelay = 500; // ms
const int MinThreads = 3;
int freeThreads;
int poolUsers;
Queue workItems = new Queue ();
AutoResetEvent threadDone = new AutoResetEvent (false);
ArrayList runningThreads = new ArrayList ();
#if TARGET_JVM
volatile
#endif
bool stopped = false;
static object globalLock = new object ();
static RemotingThreadPool sharedPool;
public static RemotingThreadPool GetSharedPool ()
{
lock (globalLock) {
if (sharedPool == null)
sharedPool = new RemotingThreadPool ();
sharedPool.poolUsers++;
}
return sharedPool;
}
public void Free ()
{
lock (globalLock) {
if (--poolUsers > 0)
return;
lock (workItems) {
stopped = true;
threadDone.Set ();
workItems.Clear ();
foreach (Thread t in runningThreads)
#if !TARGET_JVM
t.Abort ();
#else
t.Interrupt();
#endif
runningThreads.Clear ();
}
if (this == sharedPool)
sharedPool = null;
}
}
public bool RunThread (ThreadStart threadStart)
{
lock (workItems) {
if (stopped)
throw new RemotingException ("Server channel stopped.");
if (freeThreads > 0) {
freeThreads--;
workItems.Enqueue (threadStart);
Monitor.Pulse (workItems);
return true;
} else if (runningThreads.Count < MinThreads) {
workItems.Enqueue (threadStart);
StartPoolThread ();
return true;
}
}
// Try again some ms later, and if there are still no free threads,
// then create a new one
threadDone.WaitOne (PoolGrowDelay, false);
lock (workItems) {
if (stopped)
throw new RemotingException ("Server channel stopped.");
if (freeThreads > 0) {
freeThreads--;
workItems.Enqueue (threadStart);
Monitor.Pulse (workItems);
} else {
if (runningThreads.Count >= ThreadLimit)
return false;
workItems.Enqueue (threadStart);
StartPoolThread ();
}
}
return true;
}
void StartPoolThread ()
{
Thread thread = new Thread (new ThreadStart (PoolThread));
runningThreads.Add (thread);
thread.IsBackground = true;
thread.Start ();
}
void PoolThread ()
{
#if !TARGET_JVM
while (true) {
#else
while (!stopped)
{
#endif
ThreadStart work = null;
do {
lock (workItems) {
if (workItems.Count > 0)
work = (ThreadStart) workItems.Dequeue ();
else {
freeThreads ++;
threadDone.Set ();
if (!Monitor.Wait (workItems, ThreadWaitTime)) {
// Maybe it timed out when the work was being queued.
if (workItems.Count > 0) {
work = (ThreadStart) workItems.Dequeue ();
} else {
freeThreads --;
if (freeThreads == 0) threadDone.Reset ();
runningThreads.Remove (Thread.CurrentThread);
return;
}
}
}
}
} while (work == null);
try {
work ();
}
catch (Exception ex)
{
#if DEBUG
Console.WriteLine("The exception was caught during RemotingThreadPool.PoolThread - work: {0}, {1}", ex.GetType(), ex.Message);
#endif
}
}
}
}
}

View File

@@ -0,0 +1,202 @@
//
// System.Runtime.Remoting.Channels.SoapClientFormatterSink.cs
//
// Authors: Rodrigo Moya (rodrigo@ximian.com)
// Jean-Marc André (jean-marc.andre@polymtl.ca)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
using System.IO;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Soap;
namespace System.Runtime.Remoting.Channels
{
public class SoapClientFormatterSink : IClientFormatterSink,
IMessageSink, IClientChannelSink, IChannelSinkBase
{
private IClientChannelSink _nextChannelSink;
private SoapCore _soapCore = SoapCore.DefaultInstance;
public SoapClientFormatterSink (IClientChannelSink nextSink)
{
_nextChannelSink = nextSink;
}
internal SoapCore SoapCore {
get { return _soapCore; }
set { _soapCore = value; }
}
// IClientChannelSink
public IClientChannelSink NextChannelSink {
get {
return _nextChannelSink;
}
}
// IMessageSink
public IMessageSink NextSink {
get {
return null ;
}
}
// IChannelSinkBase
public IDictionary Properties {
get {
return null;
}
}
public IMessageCtrl AsyncProcessMessage (IMessage msg,
IMessageSink replySink)
{
Stream requestStream;
ITransportHeaders requestHeaders;
SoapMessageFormatter soapMsgFormatter;
SerializeMessage (msg, out requestStream, out requestHeaders,
out soapMsgFormatter);
ClientChannelSinkStack stack = new ClientChannelSinkStack (replySink);
stack.Push(this, new CallData (msg, soapMsgFormatter));
_nextChannelSink.AsyncProcessRequest (stack, msg, requestHeaders, requestStream);
return null;
}
public void AsyncProcessRequest (IClientChannelSinkStack sinkStack,
IMessage msg,
ITransportHeaders headers,
Stream stream)
{
// this method should never be called
throw new NotSupportedException ();
}
public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack,
object state,
ITransportHeaders headers,
Stream stream)
{
CallData data = (CallData) state;
SoapMessageFormatter soapMsgFormatter = data.Formatter;
IMessage replyMessage = (IMessage) DeserializeMessage (
stream, headers, (IMethodCallMessage) data.Msg,
soapMsgFormatter);
sinkStack.DispatchReplyMessage (replyMessage);
}
public Stream GetRequestStream (IMessage msg,
ITransportHeaders headers)
{
// First sink in the chain so this method should never
// be called
throw new NotSupportedException ();
}
public void ProcessMessage (IMessage msg,
ITransportHeaders requestHeaders,
Stream requestStream,
out ITransportHeaders responseHeaders,
out Stream responseStream)
{
// First sink in the chain so this method should never
// be called
throw new NotSupportedException ();
}
public IMessage SyncProcessMessage (IMessage msg)
{
Stream requestStream, responseStream;
ITransportHeaders requestHeaders, responseHeaders;
SoapMessageFormatter soapMsgFormatter;
SerializeMessage (msg, out requestStream, out requestHeaders,
out soapMsgFormatter);
_nextChannelSink.ProcessMessage(msg, requestHeaders,
requestStream, out responseHeaders,
out responseStream);
return DeserializeMessage(responseStream, responseHeaders,
(IMethodCallMessage) msg, soapMsgFormatter);
}
private void SerializeMessage(IMessage msg, out Stream requestStream, out ITransportHeaders requestHeaders, out SoapMessageFormatter soapMsgFormatter) {
SoapMessage soapMsg;
soapMsgFormatter = new SoapMessageFormatter();
soapMsg = soapMsgFormatter.BuildSoapMessageFromMethodCall (
(IMethodCallMessage) msg, out requestHeaders);
// Get the stream where the message will be serialized
requestStream = _nextChannelSink.GetRequestStream (msg,
requestHeaders);
if (requestStream == null)
requestStream = new MemoryStream();
// Serialize the message into the stream
_soapCore.Serializer.Serialize(requestStream, soapMsg, null);
if (requestStream is MemoryStream)
requestStream.Position = 0;
}
private IMessage DeserializeMessage(Stream responseStream, ITransportHeaders responseHeaders,IMethodCallMessage mcm, SoapMessageFormatter soapMsgFormatter)
{
SoapFormatter fm = _soapCore.GetSafeDeserializer ();
SoapMessage rtnMessage = soapMsgFormatter.CreateSoapMessage (false);
fm.TopObject = rtnMessage;
object objReturn = fm.Deserialize(responseStream);
if (objReturn is SoapFault)
return soapMsgFormatter.FormatFault ((SoapFault) objReturn, mcm);
else
return soapMsgFormatter.FormatResponse ((ISoapMessage) objReturn, mcm);
}
class CallData
{
public CallData (IMessage msg, SoapMessageFormatter formatter)
{
Msg = msg;
Formatter = formatter;
}
public IMessage Msg;
public SoapMessageFormatter Formatter;
}
}
}

View File

@@ -0,0 +1,63 @@
// created on 20/05/2003 at 12:33
//
// 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.Collections;
using System.Runtime.Remoting.Messaging;
namespace System.Runtime.Remoting.Channels {
public class SoapClientFormatterSinkProvider: IClientFormatterSinkProvider,
IClientChannelSinkProvider
{
private IClientChannelSinkProvider _nextClientChannelSinkProvider;
SoapCore _soapCore;
static string[] allowedProperties = new string [] { "includeVersions", "strictBinding" };
public SoapClientFormatterSinkProvider()
{
_soapCore = SoapCore.DefaultInstance;
}
public SoapClientFormatterSinkProvider(IDictionary properties,
ICollection providerData)
{
_soapCore = new SoapCore (this, properties, allowedProperties);
}
public IClientChannelSinkProvider Next
{
get { return _nextClientChannelSinkProvider;}
set { _nextClientChannelSinkProvider = value;}
}
public IClientChannelSink CreateSink( IChannelSender channel,
string url,
object remoteChannelData)
{
IClientChannelSink _nextSink = _nextClientChannelSinkProvider.CreateSink(channel, url, remoteChannelData);
SoapClientFormatterSink scfs = new SoapClientFormatterSink(_nextSink);
scfs.SoapCore = _soapCore;
return scfs;
}
}
}

View File

@@ -0,0 +1,146 @@
//
// System.Runtime.Remoting.Channels.SoapCore.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Novell, Inc.
//
//
// 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.Collections;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Soap;
namespace System.Runtime.Remoting.Channels
{
internal class SoapCore
{
SoapFormatter _serializationFormatter;
SoapFormatter _deserializationFormatter;
bool _includeVersions = true;
bool _strictBinding = false;
IDictionary _properties;
TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
public static SoapCore DefaultInstance = new SoapCore ();
public SoapCore (object owner, IDictionary properties, string[] allowedProperties)
{
_properties = properties;
if (_properties == null)
{
_properties = new Hashtable(10);
}
foreach(DictionaryEntry property in properties)
{
string key = (string) property.Key;
if (Array.IndexOf (allowedProperties, key) == -1)
throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
switch (key)
{
case "includeVersions":
_includeVersions = Convert.ToBoolean (property.Value);
break;
case "strictBinding":
_strictBinding = Convert.ToBoolean (property.Value);
break;
case "typeFilterLevel":
if (property.Value is TypeFilterLevel)
_filterLevel = (TypeFilterLevel) property.Value;
else {
string s = (string) property.Value;
_filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
}
break;
}
}
Init ();
}
public SoapCore ()
{
_properties = new Hashtable(10);
Init ();
}
public void Init ()
{
RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
_serializationFormatter = CreateFormatter (surrogateSelector, context);
_deserializationFormatter = CreateFormatter (null, context);
_serializationFormatter.FilterLevel = _filterLevel;
_deserializationFormatter.FilterLevel = _filterLevel;
}
SoapFormatter CreateFormatter (ISurrogateSelector selector, StreamingContext context)
{
SoapFormatter fm = new SoapFormatter (selector, context);
if (!_includeVersions)
fm.AssemblyFormat = FormatterAssemblyStyle.Simple;
if (!_strictBinding)
fm.Binder = ChannelCore.SimpleBinder;
return fm;
}
public SoapFormatter GetSafeDeserializer ()
{
StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
return CreateFormatter (null, context);
}
public SoapFormatter Serializer
{
get { return _serializationFormatter; }
}
public SoapFormatter Deserializer
{
get { return _deserializationFormatter; }
}
public IDictionary Properties
{
get { return _properties; }
}
public TypeFilterLevel TypeFilterLevel
{
get { return _filterLevel; }
}
}
}

View File

@@ -0,0 +1,466 @@
// created on 03/04/2003 at 14:09
//
// System.Runtime.Remoting.Channels.SoapMessageFormatter
//
// Author: Jean-Marc Andre (jean-marc.andre@polymtl.ca)
//
//
//
// 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.Collections;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
namespace System.Runtime.Remoting.Channels {
enum RemMessageType {
MethodCall, MethodResponse, ServerFault, NotRecognize
}
internal class SoapMessageFormatter {
private static FieldInfo _serverFaultExceptionField;
private Type _serverType;
private MethodInfo _methodCallInfo;
private ParameterInfo[] _methodCallParameters;
private string _xmlNamespace;
static SoapMessageFormatter() {
// Get the ServerFault exception field FieldInfo that
// will be used later if an exception occurs on the server
MemberInfo[] mi = FormatterServices.GetSerializableMembers(typeof(ServerFault), new StreamingContext(StreamingContextStates.All));
FieldInfo fi;
for(int i = 0; i < mi.Length; i++){
fi = mi[i] as FieldInfo;
if(fi != null && fi.FieldType == typeof(Exception)){
_serverFaultExceptionField = fi;
}
}
}
internal SoapMessageFormatter() {
}
internal IMessage FormatFault (SoapFault fault, IMethodCallMessage mcm)
{
ServerFault sf = fault.Detail as ServerFault;
Exception e = null;
if (sf != null) {
if(_serverFaultExceptionField != null)
e = (Exception) _serverFaultExceptionField.GetValue(sf);
#if TARGET_JVM
if (e == null && sf.ExceptionType != null)
{
try
{
Type te = Type.GetType(sf.ExceptionType);
if (te != null)
{
ConstructorInfo ce = te.GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance,
null, new Type[] {typeof(string)}, null);
if (ce != null)
{
e = (Exception) ce.Invoke(new object[] {sf.ExceptionMessage});
}
else
{
e = (Exception) Activator.CreateInstance(te);
}
}
}
catch
{
e = null;
}
}
#endif
}
if (e == null)
e = new RemotingException (fault.FaultString);
return new ReturnMessage((System.Exception)e, mcm);
}
// used by the client
internal IMessage FormatResponse(ISoapMessage soapMsg, IMethodCallMessage mcm)
{
IMessage rtnMsg;
if(soapMsg.MethodName == "Fault") {
// an exception was thrown by the server
Exception e = new SerializationException();
int i = Array.IndexOf(soapMsg.ParamNames, "detail");
if(_serverFaultExceptionField != null)
// todo: revue this 'cause it's not safe
e = (Exception) _serverFaultExceptionField.GetValue(
soapMsg.ParamValues[i]);
rtnMsg = new ReturnMessage((System.Exception)e, mcm);
}
else {
object rtnObject = null;
//RemMessageType messageType;
// Get the output of the function if it is not *void*
if(_methodCallInfo.ReturnType != typeof(void)){
int index = Array.IndexOf(soapMsg.ParamNames, "return");
rtnObject = soapMsg.ParamValues[index];
if(rtnObject is IConvertible)
rtnObject = Convert.ChangeType(
rtnObject,
_methodCallInfo.ReturnType);
}
object[] outParams = new object [_methodCallParameters.Length];
int n=0;
// check if there are *out* parameters
foreach(ParameterInfo paramInfo in _methodCallParameters) {
if(paramInfo.ParameterType.IsByRef || paramInfo.IsOut) {
int index = Array.IndexOf(soapMsg.ParamNames, paramInfo.Name);
object outParam = soapMsg.ParamValues[index];
if(outParam is IConvertible)
outParam = Convert.ChangeType (outParam, paramInfo.ParameterType.GetElementType());
outParams[n] = outParam;
}
else
outParams [n] = null;
n++;
}
Header[] headers = new Header [2 + (soapMsg.Headers != null ? soapMsg.Headers.Length : 0)];
headers [0] = new Header ("__Return", rtnObject);
headers [1] = new Header ("__OutArgs", outParams);
if (soapMsg.Headers != null)
soapMsg.Headers.CopyTo (headers, 2);
rtnMsg = new MethodResponse (headers, mcm);
}
return rtnMsg;
}
// used by the client
internal SoapMessage BuildSoapMessageFromMethodCall(
IMethodCallMessage mcm,
out ITransportHeaders requestHeaders)
{
requestHeaders = new TransportHeaders();
SoapMessage soapMsg = new SoapMessage();
GetInfoFromMethodCallMessage(mcm);
// Format the SoapMessage that will be used to create the RPC
soapMsg.MethodName = mcm.MethodName;
//int count = mcm.ArgCount;
ArrayList paramNames = new ArrayList(_methodCallParameters.Length);
ArrayList paramTypes = new ArrayList(_methodCallParameters.Length);
ArrayList paramValues = new ArrayList(_methodCallParameters.Length);
// Add the function parameters to the SoapMessage class
foreach(ParameterInfo paramInfo in _methodCallParameters) {
if (!(paramInfo.IsOut && paramInfo.ParameterType.IsByRef)) {
Type t = paramInfo.ParameterType;
if (t.IsByRef) t = t.GetElementType ();
paramNames.Add(paramInfo.Name);
paramTypes.Add(t);
paramValues.Add(mcm.Args[paramInfo.Position]);
}
}
soapMsg.ParamNames = (string[]) paramNames.ToArray(typeof(string));
soapMsg.ParamTypes = (Type[]) paramTypes.ToArray(typeof(Type));
soapMsg.ParamValues = (object[]) paramValues.ToArray(typeof(object));
soapMsg.XmlNameSpace = SoapServices.GetXmlNamespaceForMethodCall(_methodCallInfo);
soapMsg.Headers = BuildMessageHeaders (mcm);
// Format the transport headers
requestHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
requestHeaders["SOAPAction"] = "\""+
SoapServices.GetSoapActionFromMethodBase(_methodCallInfo)+"\"";
requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri;
return soapMsg;
}
// used by the server
internal IMessage BuildMethodCallFromSoapMessage(SoapMessage soapMessage, string uri)
{
ArrayList headersList = new ArrayList();
Type[] signature = null;
headersList.Add(new Header("__Uri", uri));
headersList.Add(new Header("__MethodName", soapMessage.MethodName));
string typeNamespace, assemblyName;
if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMessage.XmlNameSpace, out typeNamespace, out assemblyName))
throw new RemotingException ("Could not decode SoapMessage");
// Note that we don't need to validate the type in
// this place because MethodCall will do it anyway.
if (assemblyName == null) // corlib
_serverType = Type.GetType (typeNamespace, true);
else
_serverType = Type.GetType (typeNamespace + ", " + assemblyName, true);
headersList.Add(new Header("__TypeName", _serverType.FullName, false));
if (soapMessage.Headers != null) {
foreach (Header h in soapMessage.Headers) {
headersList.Add (h);
if (h.Name == "__MethodSignature")
signature = (Type[]) h.Value;
}
}
_xmlNamespace = soapMessage.XmlNameSpace;
//RemMessageType messageType;
BindingFlags bflags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
if (signature == null)
_methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags);
else
_methodCallInfo = _serverType.GetMethod(soapMessage.MethodName, bflags, null, signature, null);
if (_methodCallInfo == null && (soapMessage.MethodName == "FieldSetter" || soapMessage.MethodName == "FieldGetter"))
_methodCallInfo = typeof(object).GetMethod (soapMessage.MethodName, bflags);
// the *out* parameters aren't serialized
// have to add them here
_methodCallParameters = _methodCallInfo.GetParameters();
object[] args = new object[_methodCallParameters.Length];
int sn = 0;
for (int n=0; n<_methodCallParameters.Length; n++)
{
ParameterInfo paramInfo = _methodCallParameters [n];
Type paramType = (paramInfo.ParameterType.IsByRef ? paramInfo.ParameterType.GetElementType() : paramInfo.ParameterType);
if (paramInfo.IsOut && paramInfo.ParameterType.IsByRef) {
args [n] = GetNullValue (paramType);
}
else{
object val = soapMessage.ParamValues[sn++];
if(val is IConvertible)
args [n] = Convert.ChangeType (val, paramType);
else
args [n] = val;
}
}
headersList.Add(new Header("__Args", args, false));
Header[] headers = (Header[])headersList.ToArray(typeof(Header));
// build the MethodCall from the headers
MethodCall mthCall = new MethodCall(headers);
return (IMessage)mthCall;
}
// used by the server
internal object BuildSoapMessageFromMethodResponse(IMethodReturnMessage mrm, out ITransportHeaders responseHeaders)
{
responseHeaders = new TransportHeaders();
if(mrm.Exception == null) {
// *normal* function return
SoapMessage soapMessage = new SoapMessage();
// fill the transport headers
responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
// build the SoapMessage
ArrayList paramNames = new ArrayList();
ArrayList paramValues = new ArrayList();
ArrayList paramTypes = new ArrayList();
soapMessage.MethodName = mrm.MethodName+"Response";
Type retType = ((MethodInfo)mrm.MethodBase).ReturnType;
if(retType != typeof(void)) {
paramNames.Add("return");
paramValues.Add(mrm.ReturnValue);
if (mrm.ReturnValue != null)
paramTypes.Add(mrm.ReturnValue.GetType());
else
paramTypes.Add(retType);
}
for(int i = 0; i < mrm.OutArgCount; i++){
paramNames.Add(mrm.GetOutArgName(i));
paramValues.Add(mrm.GetOutArg(i));
if(mrm.GetOutArg(i) != null) paramTypes.Add(mrm.GetOutArg(i).GetType());
}
soapMessage.ParamNames = (string[]) paramNames.ToArray(typeof(string));
soapMessage.ParamValues = (object[]) paramValues.ToArray(typeof(object));
soapMessage.ParamTypes = (Type[]) paramTypes.ToArray(typeof(Type));
soapMessage.XmlNameSpace = _xmlNamespace;
soapMessage.Headers = BuildMessageHeaders (mrm);
return soapMessage;
}
else {
// an Exception was thrown while executing the function
responseHeaders["__HttpStatusCode"] = "500";
responseHeaders["__HttpReasonPhrase"] = "Bad Request";
// fill the transport headers
responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
ServerFault serverFault = CreateServerFault(mrm.Exception);
return new SoapFault("Server", String.Format(" **** {0} - {1}", mrm.Exception.GetType().ToString(), mrm.Exception.Message), null, serverFault);
}
}
internal SoapMessage CreateSoapMessage (bool isRequest)
{
if (isRequest) return new SoapMessage ();
int n = 0;
Type[] types = new Type [_methodCallParameters.Length + 1];
if (_methodCallInfo.ReturnType != typeof(void)) {
types[0] = _methodCallInfo.ReturnType;
n++;
}
foreach(ParameterInfo paramInfo in _methodCallParameters)
{
if (paramInfo.ParameterType.IsByRef || paramInfo.IsOut)
{
Type t = paramInfo.ParameterType;
if (t.IsByRef) t = t.GetElementType();
types [n++] = t;
}
}
SoapMessage sm = new SoapMessage ();
sm.ParamTypes = types;
return sm;
}
// used by the server when an exception is thrown
// by the called function
internal ServerFault CreateServerFault(Exception e) {
// it's really strange here
// a ServerFault object has a private System.Exception member called *exception*
// (have a look at a MS Soap message when an exception occurs on the server)
// but there is not public .ctor with an Exception as parameter...????....
// (maybe an internal one). So I searched another way...
ServerFault sf = (ServerFault) FormatterServices.GetUninitializedObject(typeof(ServerFault));
MemberInfo[] mi = FormatterServices.GetSerializableMembers(typeof(ServerFault), new StreamingContext(StreamingContextStates.All));
FieldInfo fi;
object[] mv = new object[mi.Length];
for(int i = 0; i < mi.Length; i++) {
fi = mi[i] as FieldInfo;
if(fi != null && fi.FieldType == typeof(Exception)) mv[i] = e;
}
sf = (ServerFault) FormatterServices.PopulateObjectMembers(sf, mi, mv);
return sf;
}
internal void GetInfoFromMethodCallMessage (IMethodMessage mcm) {
_serverType = Type.GetType(mcm.TypeName, true);
_methodCallInfo = RemotingServices.GetMethodBaseFromMethodMessage (mcm) as MethodInfo;
_methodCallParameters = _methodCallInfo.GetParameters();
}
Header[] BuildMessageHeaders (IMethodMessage msg)
{
ArrayList headers = new ArrayList (1);
foreach (string key in msg.Properties.Keys)
{
switch (key) {
case "__Uri":
case "__MethodName":
case "__TypeName":
case "__Args":
case "__OutArgs":
case "__Return":
case "__MethodSignature":
case "__CallContext":
continue;
default:
object value = msg.Properties [key];
if (value != null)
headers.Add (new Header (key, value, false, "http://schemas.microsoft.com/clr/soap/messageProperties"));
break;
}
}
if (RemotingServices.IsMethodOverloaded (msg))
headers.Add (new Header ("__MethodSignature", msg.MethodSignature, false, "http://schemas.microsoft.com/clr/soap/messageProperties"));
if (msg.LogicalCallContext != null && msg.LogicalCallContext.HasInfo)
headers.Add (new Header ("__CallContext", msg.LogicalCallContext, false, "http://schemas.microsoft.com/clr/soap/messageProperties"));
if (headers.Count == 0) return null;
return (Header[]) headers.ToArray (typeof(Header));
}
object GetNullValue (Type paramType)
{
#if TARGET_JVM
if (paramType.IsEnum)
{
return Activator.CreateInstance(paramType);
}
#endif
switch (Type.GetTypeCode (paramType))
{
case TypeCode.Boolean: return false;
case TypeCode.Byte: return (byte)0;
case TypeCode.Char: return '\0';
case TypeCode.Decimal: return (decimal)0;
case TypeCode.Double: return (double)0;
case TypeCode.Int16: return (short)0;
case TypeCode.Int32: return (int)0;
case TypeCode.Int64: return (long)0;
case TypeCode.SByte: return (sbyte)0;
case TypeCode.Single: return (float)0;
case TypeCode.UInt16: return (ushort)0;
case TypeCode.UInt32: return (uint)0;
case TypeCode.UInt64: return (ulong)0;
default:
#if TARGET_JVM
if (paramType.IsValueType)
{
return Activator.CreateInstance(paramType);
}
#endif
return null;
}
}
}
}

View File

@@ -0,0 +1,217 @@
//
// System.Runtime.Remoting.Channels.SoapServerFormatterSink.cs
//
// Authors: Duncan Mak (duncan@ximian.com)
// Jean-Marc Andre (jean-marc.andre@polymtl.ca)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
using System.IO;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting.Channels {
/// <summary>
// The formatter sink that uses SoapFormatter
/// </summary>
// <remarks>
// The formatter sink deserializes the message from the channel sink
// and passes the result to the remoting infrastructure
// </remark>
//
public class SoapServerFormatterSink : IServerChannelSink, IChannelSinkBase
{
IServerChannelSink next_sink;
IChannelReceiver _receiver;
private SoapCore _soapCore = SoapCore.DefaultInstance;
public SoapServerFormatterSink (SoapServerFormatterSink.Protocol protocol,
IServerChannelSink nextSink,
IChannelReceiver receiver)
{
this.next_sink = nextSink;
_receiver = receiver;
}
internal SoapCore SoapCore
{
get { return _soapCore; }
set { _soapCore = value; }
}
/// <summary>
// Gets the next channel sink in the channel sink chain
// </summary>
/// <value>
// The next channel sink in the sink chain
// </value>
public IServerChannelSink NextChannelSink {
get {
return next_sink;
}
}
public IDictionary Properties {
get {
return null;
}
}
[ComVisible(false)]
public TypeFilterLevel TypeFilterLevel
{
get { return _soapCore.TypeFilterLevel; }
set
{
IDictionary props = (IDictionary) ((ICloneable)_soapCore.Properties).Clone ();
props ["typeFilterLevel"] = value;
_soapCore = new SoapCore (this, props, SoapServerFormatterSinkProvider.AllowedProperties);
}
}
public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
IMessage msg, ITransportHeaders headers, Stream stream)
{
ITransportHeaders responseHeaders = new TransportHeaders();
if(sinkStack != null) stream = sinkStack.GetResponseStream(msg, responseHeaders);
if(stream == null) stream = new MemoryStream();
SoapMessageFormatter soapMsgFormatter = (SoapMessageFormatter)state;
SoapMessage soapMessage = (SoapMessage) soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage)msg, out responseHeaders);
_soapCore.Serializer.Serialize(stream, soapMessage, null);
if(stream is MemoryStream) stream.Position = 0;
sinkStack.AsyncProcessResponse (msg, responseHeaders, stream);
}
public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack, object state,
IMessage msg, ITransportHeaders headers)
{
// this method shouldn't be called
throw new NotSupportedException ();
}
public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
{
// Check whether the request was already processed by another
// formatter sink and pass the request to the next sink if so.
if (requestMsg != null)
return next_sink.ProcessMessage (sinkStack,
requestMsg,
requestHeaders,
requestStream,
out responseMsg,
out responseHeaders,
out responseStream);
// Check whether the request is suitable for this formatter
// and pass the request to the next sink if not.
// Note that a null content-type is handled as suitable,
// otherwise no other sink will be able to handle the request.
string contentType = requestHeaders["Content-Type"] as string;
if (contentType == null || !contentType.StartsWith ("text/xml") || requestHeaders["SOAPAction"] == null) {
return next_sink.ProcessMessage (sinkStack,
requestMsg,
requestHeaders,
requestStream,
out responseMsg,
out responseHeaders,
out responseStream);
}
responseMsg = null;
responseHeaders = null;
responseStream = null;
ServerProcessing sp;
SoapMessageFormatter soapMsgFormatter = new SoapMessageFormatter();
sinkStack.Push(this, soapMsgFormatter);
try {
string url = (string)requestHeaders[CommonTransportKeys.RequestUri];
string uri;
_receiver.Parse(url, out uri);
if(uri == null) uri = url;
Type serverType = RemotingServices.GetServerTypeForUri(uri);
if (serverType == null) throw new RemotingException ("No receiver for uri " + uri);
SoapFormatter fm = _soapCore.GetSafeDeserializer ();
SoapMessage soapMessage = soapMsgFormatter.CreateSoapMessage (true);
fm.TopObject = soapMessage;
fm.Deserialize(requestStream);
requestMsg = soapMsgFormatter.BuildMethodCallFromSoapMessage(soapMessage, uri);
sp = next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
if(sp == ServerProcessing.Complete) {
if(responseMsg != null && responseStream == null) {
object rtnMessageObject = soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage) responseMsg, out responseHeaders);
responseStream = new MemoryStream();
_soapCore.Serializer.Serialize(responseStream, rtnMessageObject);
responseStream.Position = 0;
}
}
}
catch(Exception e)
{
responseMsg = (IMethodReturnMessage)new ReturnMessage(e, (IMethodCallMessage)requestMsg);
object rtnMessageObject = soapMsgFormatter.BuildSoapMessageFromMethodResponse((IMethodReturnMessage) responseMsg, out responseHeaders);
responseStream = new MemoryStream();
_soapCore.Serializer.Serialize(responseStream, rtnMessageObject);
responseStream.Position = 0;
sp = ServerProcessing.Complete;
}
if (sp == ServerProcessing.Complete)
sinkStack.Pop(this);
return sp;
}
[Serializable]
public enum Protocol
{
Http = 0,
Other = 1,
}
}
}

View File

@@ -0,0 +1,90 @@
//
// System.Runtime.Remoting.Channels.SoapServerFormatterSinkProvider.cs
//
// Author: Rodrigo Moya (rodrigo@ximian.com)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// 2002 (C) Copyright, Ximian, Inc.
//
//
// 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.Collections;
using System.Runtime.Serialization.Formatters;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting.Channels
{
public class SoapServerFormatterSinkProvider :
IServerFormatterSinkProvider, IServerChannelSinkProvider
{
private IServerChannelSinkProvider _next;
SoapCore _soapCore;
internal static string[] AllowedProperties = new string [] { "includeVersions", "strictBinding", "typeFilterLevel" };
public SoapServerFormatterSinkProvider ()
{
_soapCore = SoapCore.DefaultInstance;
}
public SoapServerFormatterSinkProvider (IDictionary properties,
ICollection providerData)
{
_soapCore = new SoapCore (this, properties, AllowedProperties);
}
public IServerChannelSinkProvider Next
{
get { return _next; }
set { _next = value; }
}
[ComVisible(false)]
public TypeFilterLevel TypeFilterLevel
{
get { return _soapCore.TypeFilterLevel; }
set
{
IDictionary props = (IDictionary) ((ICloneable)_soapCore.Properties).Clone ();
props ["typeFilterLevel"] = value;
_soapCore = new SoapCore (this, props, AllowedProperties);
}
}
public IServerChannelSink CreateSink (IChannelReceiver channel)
{
IServerChannelSink chain = _next.CreateSink(channel);
SoapServerFormatterSink sinkFormatter = new SoapServerFormatterSink(SoapServerFormatterSink.Protocol.Http, chain, channel);
sinkFormatter.SoapCore = _soapCore;
return sinkFormatter;
}
public void GetChannelData (IChannelDataStore channelData)
{
if(_next != null)
_next.GetChannelData(channelData);
}
}
}

View File

@@ -0,0 +1,41 @@
//
// System.Runtime.Remoting.Channels.SocketCachePolicy.cs
//
// Author:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (C) Copyright 2008 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.
//
#if NET_2_0
namespace System.Runtime.Remoting.Channels
{
public enum SocketCachePolicy
{
Default,
AbsoluteTimeout
}
}
#endif