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,87 @@
//
// System.ServiceModel.ActionMessageFilter.cs
//
// Author: Duncan Mak (duncan@novell.com)
//
// 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.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Dispatcher {
[DataContract]
public class ActionMessageFilter : MessageFilter
{
ReadOnlyCollection<string> actions;
public ActionMessageFilter (params string [] actions)
{
if (actions == null)
throw new ArgumentNullException ("actions");
// remove duplicates
List<string> l = new List<string> ();
foreach (string action in actions) {
if (action == null)
throw new ArgumentNullException ("actions");
if (l.Contains (action) == false)
l.Add (action);
}
this.actions = new ReadOnlyCollection<string> (l);
}
protected internal override IMessageFilterTable<FilterData> CreateFilterTable<FilterData> ()
{
return new ActionMessageFilterTable<FilterData> ();
}
public override bool Match (Message message)
{
foreach (string action in actions)
if (message.Headers.Action == action || action == "*")
return true;
return false;
}
public override bool Match (MessageBuffer buffer)
{
bool retval;
Message m = buffer.CreateMessage ();
retval = Match (m);
m.Close ();
return retval;
}
public ReadOnlyCollection<string> Actions {
get { return actions; }
}
}
}

View File

@@ -0,0 +1,186 @@
//
// System.ServiceModel.ActionMessageFilterTable.cs
//
// Author: Duncan Mak (duncan@novell.com)
//
// 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.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Dispatcher {
[DataContract]
internal class ActionMessageFilterTable<TFilterData>
: IMessageFilterTable<TFilterData>,
IDictionary<MessageFilter,TFilterData>,
ICollection<KeyValuePair<MessageFilter, TFilterData>>,
IEnumerable<KeyValuePair<MessageFilter,TFilterData>>,
IEnumerable
{
Dictionary<MessageFilter, TFilterData> table;
public ActionMessageFilterTable ()
{
table = new Dictionary<MessageFilter, TFilterData> ();
}
public void Add (KeyValuePair<MessageFilter, TFilterData> item)
{
table.Add (item.Key, item.Value);
}
public void Add (ActionMessageFilter filter, TFilterData data)
{
table.Add (filter, data);
}
public void Add (MessageFilter filter, TFilterData data)
{
table.Add (filter, data);
}
public void Clear ()
{
table.Clear ();
}
public bool Contains (KeyValuePair<MessageFilter, TFilterData> item)
{
return table.ContainsKey (item.Key);
}
public bool ContainsKey (MessageFilter filter)
{
return table.ContainsKey (filter);
}
public void CopyTo (KeyValuePair<MessageFilter, TFilterData> [] array, int index)
{
((ICollection<KeyValuePair<MessageFilter, TFilterData>>) table).CopyTo (array, index);
}
public IEnumerator<KeyValuePair<MessageFilter, TFilterData>> GetEnumerator ()
{
return ((ICollection<KeyValuePair<MessageFilter, TFilterData>>) table).GetEnumerator ();
}
public bool GetMatchingFilter (Message message, out MessageFilter result)
{
throw new NotImplementedException ();
}
public bool GetMatchingFilter (MessageBuffer buffer, out MessageFilter result)
{
throw new NotImplementedException ();
}
public bool GetMatchingFilters (Message message, ICollection<MessageFilter> results)
{
throw new NotImplementedException ();
}
public bool GetMatchingFilters (MessageBuffer buffer, ICollection<MessageFilter> results)
{
throw new NotImplementedException ();
}
public bool GetMatchingValue (Message message, out TFilterData data)
{
throw new NotImplementedException ();
}
public bool GetMatchingValue (MessageBuffer buffer, out TFilterData data)
{
throw new NotImplementedException ();
}
public bool GetMatchingValues (Message message, ICollection<TFilterData> results)
{
throw new NotImplementedException ();
}
public bool GetMatchingValues (MessageBuffer buffer, ICollection<TFilterData> results)
{
throw new NotImplementedException ();
}
public bool Remove (ActionMessageFilter filter)
{
if (filter == null)
throw new ArgumentNullException ("filter is null.");
return table.Remove (filter);
}
public bool Remove (MessageFilter filter)
{
if (filter == null)
throw new ArgumentNullException ("filter is null.");
return table.Remove (filter);
}
public bool Remove (KeyValuePair<MessageFilter, TFilterData> item)
{
return table.Remove (item.Key);
}
IEnumerator IEnumerable.GetEnumerator ()
{
return table.GetEnumerator ();
}
public bool TryGetValue (MessageFilter filter, out TFilterData data)
{
if (table.ContainsKey (filter)){
data = table [filter];
return true;
}
data = default (TFilterData);
return false;
}
public int Count { get { return table.Count; }}
public bool IsReadOnly { get { return false; }}
public TFilterData this [MessageFilter filter] {
get { return table [filter]; }
set { table [filter] = value; }
}
public ICollection<MessageFilter> Keys {
get { return table.Keys; }
}
public ICollection<TFilterData> Values {
get { return table.Values; }
}
}
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using System.Text;
namespace System.ServiceModel.Dispatcher
{
internal class BaseRequestProcessor
{
HandlersChain initialize_handlers_chain = new HandlersChain();
HandlersChain process_handlers_chain = new HandlersChain ();
HandlersChain error_handlers_chain = new HandlersChain ();
HandlersChain finalize_handlers_chain = new HandlersChain ();
protected BaseRequestProcessor () { }
protected virtual void ProcessRequest (MessageProcessingContext mrc)
{
initialize_handlers_chain.ProcessRequestChain (mrc);
using (new OperationContextScope (mrc.OperationContext)) {
try {
process_handlers_chain.ProcessRequestChain (mrc);
}
catch (Exception e) {
// FIXME: this is not really expected use of ChannelDispatcher.ErrorHandlers.
// They are now correctly used in process_handler_chain (namely OperationInvokerHandler).
// For this kind of "outsider" exceptions are actually left thrown
// (and could even cause server loop crash in .NET).
Console.WriteLine ("Exception " + e.Message + " " + e.StackTrace);
mrc.ProcessingException = e;
error_handlers_chain.ProcessRequestChain (mrc);
}
finally {
finalize_handlers_chain.ProcessRequestChain (mrc);
}
}
}
public HandlersChain InitializeChain
{
get { return initialize_handlers_chain; }
}
public HandlersChain ProcessingChain
{
get { return process_handlers_chain; }
}
public HandlersChain ErrorChain
{
get { return error_handlers_chain; }
}
public HandlersChain FinalizationChain
{
get { return finalize_handlers_chain; }
}
}
internal class HandlersChain
{
BaseRequestProcessorHandler chain;
public void ProcessRequestChain (MessageProcessingContext mrc)
{
if (chain != null)
chain.ProcessRequestChain (mrc);
}
public HandlersChain AddHandler (BaseRequestProcessorHandler handler)
{
if (chain == null) {
chain = handler;
}
else {
BaseRequestProcessorHandler current = chain;
while (current.Next != null)
current = current.Next;
current.Next = handler;
}
return this;
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Dispatcher
{
internal abstract class BaseRequestProcessorHandler
{
BaseRequestProcessorHandler next;
public virtual void ProcessRequestChain (MessageProcessingContext mrc)
{
if (!ProcessRequest (mrc) && next != null ) {
next.ProcessRequestChain (mrc);
}
}
public BaseRequestProcessorHandler Next
{
get { return next; }
set { next = value; }
}
protected abstract bool ProcessRequest (MessageProcessingContext mrc);
}
}

View File

@@ -0,0 +1,64 @@
//
// CallbackInstanceContextProvider.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 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.
//
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Dispatcher
{
internal class CallbackInstanceContextProvider : IInstanceContextProvider
{
InstanceContext ctx;
public CallbackInstanceContextProvider (InstanceContext context)
{
this.ctx = context;
}
public InstanceContext GetExistingInstanceContext (Message message, IContextChannel channel)
{
return ctx;
}
public void InitializeInstanceContext (InstanceContext instanceContext, Message message, IContextChannel channel)
{
// FIXME: what to do here?
}
public bool IsIdle (InstanceContext instanceContext)
{
// FIXME: implement
throw new NotImplementedException ();
}
public void NotifyIdle (InstanceContextIdleCallback callback, InstanceContext instanceContext)
{
// FIXME: implement
throw new NotImplementedException ();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,57 @@
//
// ChannelDispatcherBase.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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.
//
using System;
using System.Reflection;
using System.ServiceModel.Channels;
using System.Threading;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Dispatcher
{
public abstract class ChannelDispatcherBase : CommunicationObject
{
internal bool IsMex { get; set; }
public abstract IChannelListener Listener { get; }
public abstract ServiceHostBase Host { get; }
protected internal virtual void Attach (ServiceHostBase host)
{
}
public virtual void CloseInput ()
{
}
protected internal virtual void Detach (ServiceHostBase host)
{
}
}
}

View File

@@ -0,0 +1,71 @@
//
// ChannelDispatcherCollection.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace System.ServiceModel.Dispatcher
{
public class ChannelDispatcherCollection
: SynchronizedCollection<ChannelDispatcherBase>
{
private ServiceHostBase _service;
internal ChannelDispatcherCollection (ServiceHostBase service)
{
_service = service;
}
protected override void ClearItems ()
{
foreach (ChannelDispatcherBase c in this)
c.Detach (_service);
base.ClearItems ();
}
protected override void InsertItem (int index, ChannelDispatcherBase item)
{
item.Attach (_service);
base.InsertItem (index, item);
}
protected override void RemoveItem (int index)
{
ChannelDispatcherBase removed = this [index];
base.RemoveItem (index);
removed.Detach (_service);
}
protected override void SetItem (int index, ChannelDispatcherBase item)
{
item.Attach (_service);
base.SetItem (index, item);
}
}
}

View File

@@ -0,0 +1,209 @@
//
// ClientOperation.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
namespace System.ServiceModel.Dispatcher
{
public sealed class ClientOperation
{
internal class ClientOperationCollection :
#if NET_2_1
KeyedCollection<string, ClientOperation>
#else
SynchronizedKeyedCollection<string, ClientOperation>
#endif
{
protected override string GetKeyForItem (ClientOperation o)
{
return o.Name;
}
}
ClientRuntime parent;
string name, action, reply_action;
MethodInfo sync_method, begin_method, end_method;
bool deserialize_reply = true, serialize_request = true;
bool is_initiating, is_terminating, is_oneway;
IClientMessageFormatter formatter;
SynchronizedCollection<IParameterInspector> inspectors
= new SynchronizedCollection<IParameterInspector> ();
SynchronizedCollection<FaultContractInfo> fault_contract_infos = new SynchronizedCollection<FaultContractInfo> ();
public ClientOperation (ClientRuntime parent,
string name, string action)
{
this.parent = parent;
this.name = name;
this.action = action;
}
public ClientOperation (ClientRuntime parent,
string name, string action, string replyAction)
{
this.parent = parent;
this.name = name;
this.action = action;
this.reply_action = replyAction;
}
public string Action {
get { return action; }
}
public string ReplyAction {
get { return reply_action; }
}
public MethodInfo BeginMethod {
get { return begin_method; }
set {
ThrowIfOpened ();
begin_method = value;
}
}
public bool DeserializeReply {
get { return deserialize_reply; }
set {
ThrowIfOpened ();
deserialize_reply = value;
}
}
public MethodInfo EndMethod {
get { return end_method; }
set {
ThrowIfOpened ();
end_method = value;
}
}
public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
get { return fault_contract_infos; }
}
public IClientMessageFormatter Formatter {
get { return formatter; }
set {
ThrowIfOpened ();
formatter = value;
}
}
public bool IsInitiating {
get { return is_initiating; }
set {
ThrowIfOpened ();
is_initiating = value;
}
}
public bool IsOneWay {
get { return is_oneway; }
set {
ThrowIfOpened ();
is_oneway = value;
}
}
public bool IsTerminating {
get { return is_terminating; }
set {
ThrowIfOpened ();
is_terminating = value;
}
}
public string Name {
get { return name; }
}
public SynchronizedCollection<IParameterInspector> ParameterInspectors {
get { return inspectors; }
}
public ClientRuntime Parent {
get { return parent; }
}
public bool SerializeRequest {
get { return serialize_request; }
set {
ThrowIfOpened ();
serialize_request = value;
}
}
public MethodInfo SyncMethod {
get { return sync_method; }
set {
ThrowIfOpened ();
sync_method = value;
}
}
void ThrowIfOpened ()
{
// FIXME: get correct state
var state = CommunicationState.Created;
switch (state) {
case CommunicationState.Created:
case CommunicationState.Opening:
return;
}
throw new InvalidOperationException ("Cannot change this property after the service host is opened");
}
#if NET_4_5
[MonoTODO]
public ICollection<IParameterInspector> ClientParameterInspectors {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public MethodInfo TaskMethod {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
[MonoTODO]
public Type TaskTResult {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
#endif
}
}

View File

@@ -0,0 +1,149 @@
//
// ClientRuntime.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 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.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
namespace System.ServiceModel.Dispatcher
{
public sealed class ClientRuntime
{
SynchronizedCollection<IChannelInitializer> channel_initializers
= new SynchronizedCollection<IChannelInitializer> ();
SynchronizedCollection<IInteractiveChannelInitializer> interactive_channel_initializers
= new SynchronizedCollection<IInteractiveChannelInitializer> ();
SynchronizedCollection<IClientMessageInspector> inspectors
= new SynchronizedCollection<IClientMessageInspector> ();
ClientOperation.ClientOperationCollection operations
= new ClientOperation.ClientOperationCollection ();
IClientOperationSelector selector;
Uri via;
bool validate, manual_addressing;
string contract_name, contract_ns;
int max_fault_size = 0x10000; // FIXME: not verified.
// .ctor() for Clients
internal ClientRuntime (string name, string ns, object callbackDispatchRuntime)
{
contract_name = name;
contract_ns = ns;
#if !NET_2_1
CallbackDispatchRuntime = (DispatchRuntime) callbackDispatchRuntime ?? new DispatchRuntime (null, this);
#endif
}
public Type CallbackClientType { get; set; }
public SynchronizedCollection<IChannelInitializer> ChannelInitializers {
get { return channel_initializers; }
}
public SynchronizedCollection<IInteractiveChannelInitializer> InteractiveChannelInitializers {
get { return interactive_channel_initializers;}
}
public string ContractName {
get { return contract_name; }
}
public string ContractNamespace {
get { return contract_ns; }
}
public Type ContractClientType { get; set; }
#if !NET_2_1
public DispatchRuntime CallbackDispatchRuntime { get; internal set; }
#endif
public SynchronizedCollection<IClientMessageInspector> MessageInspectors {
get { return inspectors; }
}
#if NET_2_1
public KeyedCollection<string,ClientOperation> Operations {
get { return operations; }
}
#else
public SynchronizedKeyedCollection<string,ClientOperation> Operations {
get { return operations; }
}
#endif
#if NET_4_5
[MonoTODO]
public ICollection<ClientOperation> ClientOperations {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public ICollection<IClientMessageInspector> ClientMessageInspectors {
get { throw new NotImplementedException (); }
}
#endif
public bool ManualAddressing {
get { return manual_addressing; }
set { manual_addressing = value; }
}
public int MaxFaultSize {
get { return max_fault_size; }
set { max_fault_size = value; }
}
public IClientOperationSelector OperationSelector {
get { return selector; }
set { selector = value; }
}
public bool ValidateMustUnderstand {
get { return validate; }
set { validate = value; }
}
public Uri Via {
get { return via; }
set { via = value; }
}
[MonoTODO]
public ClientOperation UnhandledClientOperation {
get { throw new NotImplementedException (); }
}
[MonoTODO]
public bool MessageVersionNoneFaultsEnabled {
get { throw new NotImplementedException (); }
set { throw new NotImplementedException (); }
}
}
}

View File

@@ -0,0 +1,73 @@
//
// DataContractSerializerServiceBehavior.cs
//
// Author:
// Igor Zelmanovich <igorz@mainsoft.com>
//
// Copyright (C) 2008 Mainsoft, Inc. http://www.mainsoft.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.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel.Description;
namespace System.ServiceModel.Dispatcher
{
class DataContractSerializerServiceBehavior : IEndpointBehavior
{
public bool IgnoreExtensionDataObject {
get;
set;
}
public int MaxItemsInObjectGraph {
get;
set;
}
public DataContractSerializerServiceBehavior (bool ignoreExtensionDataObject, int maxItemsInObjectGraph) {
IgnoreExtensionDataObject = ignoreExtensionDataObject;
MaxItemsInObjectGraph = maxItemsInObjectGraph;
}
#region IEndpointBehavior Members
void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection parameters) {
throw new NotImplementedException ();
}
void IEndpointBehavior.ApplyDispatchBehavior (ServiceEndpoint serviceEndpoint, EndpointDispatcher dispatcher) {
throw new NotImplementedException ();
}
void IEndpointBehavior.ApplyClientBehavior (ServiceEndpoint serviceEndpoint, ClientRuntime behavior) {
throw new NotImplementedException ();
}
void IEndpointBehavior.Validate (ServiceEndpoint serviceEndpoint) {
throw new NotImplementedException ();
}
#endregion
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace System.ServiceModel.Dispatcher
{
class DefaultInstanceContextProvider : IInstanceContextProvider
{
public InstanceContext GetExistingInstanceContext (System.ServiceModel.Channels.Message message, IContextChannel channel) {
return null;
}
public void InitializeInstanceContext (InstanceContext instanceContext, System.ServiceModel.Channels.Message message, IContextChannel channel) {
}
public bool IsIdle (InstanceContext instanceContext) {
return true;
}
public void NotifyIdle (InstanceContextIdleCallback callback, InstanceContext instanceContext) {
}
}
}

View File

@@ -0,0 +1,133 @@
//
// DefaultOperationInvoker.cs
//
// Author: Atsushi Enomoto (atsushi@ximian.com)
//
// Copyright (C) 2009 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.
//
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Reflection;
using System.Threading;
namespace System.ServiceModel.Dispatcher
{
class DefaultOperationInvoker : IOperationInvoker
{
readonly OperationDescription od;
readonly ParameterInfo [] in_params, out_params;
readonly bool is_synchronous;
public DefaultOperationInvoker (OperationDescription od)
{
this.od = od;
is_synchronous = od.SyncMethod != null;
var mi = od.SyncMethod ?? od.BeginMethod;
var il = new List<ParameterInfo> ();
var ol = new List<ParameterInfo> ();
var pl = mi.GetParameters ();
int count = mi == od.BeginMethod ? pl.Length - 2 : pl.Length;
for (int i = 0; i < count; i++) {
var pi = pl [i];
if (!pi.IsOut)
il.Add (pi);
if (pi.IsOut || pi.ParameterType.IsByRef)
ol.Add (pi);
}
in_params = il.ToArray ();
out_params = ol.ToArray ();
}
public bool IsSynchronous {
get { return is_synchronous; }
}
public object [] AllocateInputs ()
{
return new object [in_params.Length];
}
public object Invoke (object instance, object [] inputs, out object [] outputs)
{
var arr = new object [od.SyncMethod.GetParameters ().Length];
for (int i = 0; i < in_params.Length; i++)
arr [in_params [i].Position] = inputs [i];
var ret = od.SyncMethod.Invoke (instance, arr);
outputs = new object [out_params.Length];
for (int i = 0; i < out_params.Length; i++)
outputs [i] = arr [out_params [i].Position];
return ret;
}
public IAsyncResult InvokeBegin (object instance, object [] inputs, AsyncCallback callback, object state)
{
var arr = new object [in_params.Length + out_params.Length + 2];
for (int i = 0; i < in_params.Length; i++)
arr [in_params [i].Position] = inputs [i];
arr [arr.Length - 2] = callback;
arr [arr.Length - 1] = state;
return new InvokeAsyncResult (arr, (IAsyncResult) od.BeginMethod.Invoke (instance, arr));
}
public object InvokeEnd (object instance, out object [] outputs, IAsyncResult result)
{
var r = (InvokeAsyncResult) result;
var ret = od.EndMethod.Invoke (instance, new object [] {r.Source});
var arr = r.Parameters;
outputs = new object [out_params.Length];
for (int i = 0; i < out_params.Length; i++)
outputs [i] = arr [out_params [i].Position];
return ret;
}
class InvokeAsyncResult : IAsyncResult
{
public InvokeAsyncResult (object [] parameters, IAsyncResult source)
{
Source = source;
Parameters = parameters;
}
public IAsyncResult Source;
public object [] Parameters;
public WaitHandle AsyncWaitHandle {
get { return Source.AsyncWaitHandle; }
}
public bool CompletedSynchronously {
get { return Source.CompletedSynchronously; }
}
public bool IsCompleted {
get { return Source.IsCompleted; }
}
public object AsyncState {
get { return Source.AsyncState; }
}
}
}
}

View File

@@ -0,0 +1,230 @@
//
// DispatchOperation.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2010 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.
//
using System;
using System.Collections.Generic;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
namespace System.ServiceModel.Dispatcher
{
public sealed class DispatchOperation
{
internal class DispatchOperationCollection :
SynchronizedKeyedCollection<string, DispatchOperation>
{
protected override string GetKeyForItem (DispatchOperation o)
{
return o.Name;
}
}
DispatchRuntime parent;
string name, action, reply_action;
bool serialize_reply = true, deserialize_request = true,
is_oneway, is_terminating,
release_after_call, release_before_call,
tx_auto_complete, tx_required,
auto_dispose_params = true;
IDispatchMessageFormatter formatter;
#if !NET_2_1
ImpersonationOption impersonation;
IOperationInvoker invoker;
SynchronizedCollection<IParameterInspector> inspectors
= new SynchronizedCollection<IParameterInspector> ();
SynchronizedCollection<FaultContractInfo> fault_contract_infos
= new SynchronizedCollection<FaultContractInfo> ();
SynchronizedCollection<ICallContextInitializer> ctx_initializers
= new SynchronizedCollection<ICallContextInitializer> ();
#endif
public DispatchOperation (DispatchRuntime parent,
string name, string action)
{
if (parent == null)
throw new ArgumentNullException ("parent");
if (name == null)
throw new ArgumentNullException ("name");
// action could be null
is_oneway = true;
this.parent = parent;
this.name = name;
this.action = action;
}
public DispatchOperation (DispatchRuntime parent,
string name, string action, string replyAction)
: this (parent, name, action)
{
// replyAction could be null
is_oneway = false;
reply_action = replyAction;
}
public string Action {
get { return action; }
}
#if !NET_2_1
public SynchronizedCollection<ICallContextInitializer> CallContextInitializers {
get { return ctx_initializers; }
}
public SynchronizedCollection<FaultContractInfo> FaultContractInfos {
get { return fault_contract_infos; }
}
[MonoTODO ("not considered")]
public ImpersonationOption Impersonation {
get { return impersonation; }
set {
ThrowIfOpened ();
impersonation = value;
}
}
public IOperationInvoker Invoker {
get { return invoker; }
set {
ThrowIfOpened ();
invoker = value;
}
}
public bool IsTerminating {
get { return is_terminating; }
set {
ThrowIfOpened ();
is_terminating = value;
}
}
public SynchronizedCollection<IParameterInspector> ParameterInspectors {
get { return inspectors; }
}
public bool ReleaseInstanceAfterCall {
get { return release_after_call; }
set {
ThrowIfOpened ();
release_after_call = value;
}
}
public bool ReleaseInstanceBeforeCall {
get { return release_before_call; }
set {
ThrowIfOpened ();
release_before_call = value;
}
}
public string ReplyAction {
get { return reply_action; }
}
public bool TransactionAutoComplete {
get { return tx_auto_complete; }
set {
ThrowIfOpened ();
tx_auto_complete = value;
}
}
public bool TransactionRequired {
get { return tx_required; }
set {
ThrowIfOpened ();
tx_required = value;
}
}
#endif
public bool AutoDisposeParameters {
get { return auto_dispose_params; }
set {
ThrowIfOpened ();
auto_dispose_params = value;
}
}
public bool DeserializeRequest {
get { return deserialize_request; }
set {
ThrowIfOpened ();
deserialize_request = value;
}
}
public IDispatchMessageFormatter Formatter {
get { return formatter; }
set {
ThrowIfOpened ();
formatter = value;
}
}
public bool IsOneWay {
get { return is_oneway; }
}
public string Name {
get { return name; }
}
public DispatchRuntime Parent {
get { return parent; }
}
public bool SerializeReply {
get { return serialize_reply; }
set {
ThrowIfOpened ();
serialize_reply = value;
}
}
void ThrowIfOpened ()
{
#if !NET_2_1
// FIXME: get callback client runtime status when ChannelDispatcher is not available.
var state = Parent.ChannelDispatcher != null ? Parent.ChannelDispatcher.State : CommunicationState.Created; // Parent.CallbackClientRuntime.ChannelFactory.State;
switch (state) {
case CommunicationState.Created:
case CommunicationState.Opening:
return;
}
throw new InvalidOperationException ("Cannot change this property after the service host is opened");
#endif
}
}
}

View File

@@ -0,0 +1,154 @@
//
// DispatchRuntime.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2010 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.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
#if !NET_2_1
using System.IdentityModel.Policy;
using System.Web.Security;
#endif
using System.Text;
using System.Threading;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
namespace System.ServiceModel.Dispatcher
{
public sealed class DispatchRuntime
{
#if NET_2_1
internal DispatchRuntime (EndpointDispatcher dispatcher, ClientRuntime callbackClientRuntime)
{
UnhandledDispatchOperation = new DispatchOperation (
this, "*", "*", "*");
}
#else
DispatchOperation.DispatchOperationCollection operations =
new DispatchOperation.DispatchOperationCollection ();
internal DispatchRuntime (EndpointDispatcher dispatcher, ClientRuntime callbackClientRuntime)
{
EndpointDispatcher = dispatcher;
CallbackClientRuntime = callbackClientRuntime ?? new ClientRuntime (EndpointDispatcher.ContractName, EndpointDispatcher.ContractNamespace, this);
UnhandledDispatchOperation = new DispatchOperation (
this, "*", "*", "*");
AutomaticInputSessionShutdown = true;
PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups; // silly default value for us.
SuppressAuditFailure = true;
ValidateMustUnderstand = true;
InputSessionShutdownHandlers = new SynchronizedCollection<IInputSessionShutdown> ();
InstanceContextInitializers = new SynchronizedCollection<IInstanceContextInitializer> ();
MessageInspectors = new SynchronizedCollection<IDispatchMessageInspector> ();
}
[MonoTODO]
public AuditLogLocation SecurityAuditLogLocation { get; set; }
[MonoTODO]
public bool AutomaticInputSessionShutdown { get; set; }
public ChannelDispatcher ChannelDispatcher {
get { return EndpointDispatcher.ChannelDispatcher; }
}
[MonoTODO]
public ConcurrencyMode ConcurrencyMode { get; set; }
public EndpointDispatcher EndpointDispatcher { get; private set; }
public ClientRuntime CallbackClientRuntime { get; internal set; }
[MonoTODO]
public ReadOnlyCollection<IAuthorizationPolicy> ExternalAuthorizationPolicies { get; set; }
[MonoTODO]
public bool IgnoreTransactionMessageProperty { get; set; }
[MonoTODO]
public bool ImpersonateCallerForAllOperations { get; set; }
[MonoTODO]
public SynchronizedCollection<IInputSessionShutdown> InputSessionShutdownHandlers { get; private set; }
[MonoTODO]
public SynchronizedCollection<IInstanceContextInitializer> InstanceContextInitializers { get; private set; }
public IInstanceProvider InstanceProvider { get; set; }
public IInstanceContextProvider InstanceContextProvider { get; set; }
[MonoTODO]
public AuditLevel MessageAuthenticationAuditLevel { get; set; }
public SynchronizedCollection<IDispatchMessageInspector> MessageInspectors { get; private set; }
public SynchronizedKeyedCollection<string,DispatchOperation> Operations {
get { return operations; }
}
public IDispatchOperationSelector OperationSelector { get; set; }
[MonoTODO]
public PrincipalPermissionMode PrincipalPermissionMode { get; set; }
[MonoTODO]
public bool ReleaseServiceInstanceOnTransactionComplete { get; set; }
[MonoTODO]
public RoleProvider RoleProvider { get; set; }
[MonoTODO]
public AuditLevel ServiceAuthorizationAuditLevel { get; set; }
[MonoTODO]
public ServiceAuthorizationManager ServiceAuthorizationManager { get; set; }
public InstanceContext SingletonInstanceContext { get; set; }
[MonoTODO]
public bool SuppressAuditFailure { get; set; }
[MonoTODO]
public SynchronizationContext SynchronizationContext { get; set; }
[MonoTODO]
public bool TransactionAutoCompleteOnSessionClose { get; set; }
public Type Type { get; set; }
public bool ValidateMustUnderstand { get; set; }
#endif
public DispatchOperation UnhandledDispatchOperation { get; set; }
}
}

View File

@@ -0,0 +1,89 @@
//
// EndpointAddressMessageFilter.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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.
//
using System;
using System.ServiceModel.Channels;
using System.ServiceModel;
namespace System.ServiceModel.Dispatcher
{
public class EndpointAddressMessageFilter : MessageFilter
{
EndpointAddress address;
bool cmp_host;
public EndpointAddressMessageFilter (EndpointAddress address)
: this (address, false)
{
}
public EndpointAddressMessageFilter (EndpointAddress address,
bool includeHostNameInComparison)
{
if (address == null)
throw new ArgumentNullException ("address");
this.address = address;
cmp_host = includeHostNameInComparison;
}
public EndpointAddress Address {
get { return address; }
}
public bool IncludeHostNameInComparison {
get { return cmp_host; }
}
[MonoTODO]
protected internal override IMessageFilterTable<FilterData>
CreateFilterTable<FilterData> ()
{
throw new NotImplementedException ();
}
public override bool Match (Message message)
{
Uri to = message.Headers.To;
if (to == null)
return false;
bool path = ((String.CompareOrdinal (to.AbsolutePath, address.Uri.AbsolutePath) == 0) &&
(to.Port == address.Uri.Port));
bool host = IncludeHostNameInComparison
? (String.CompareOrdinal (to.Host, address.Uri.Host) == 0)
: true;
return path && host;
}
public override bool Match (MessageBuffer messageBuffer)
{
if (messageBuffer == null)
throw new ArgumentNullException ("messageBuffer");
return Match (messageBuffer.CreateMessage ());
}
}
}

View File

@@ -0,0 +1,192 @@
//
// EndpointAddressMessageFilterTable.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 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.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace System.ServiceModel.Dispatcher
{
internal class EndpointAddressMessageFilterTable<TFilterData>
: IDictionary<MessageFilter,TFilterData>,
IMessageFilterTable<TFilterData>,
IEnumerable,
ICollection<KeyValuePair<MessageFilter,TFilterData>>,
IEnumerable<KeyValuePair<MessageFilter,TFilterData>>
{
Dictionary<MessageFilter,TFilterData> dict
= new Dictionary<MessageFilter,TFilterData> ();
public EndpointAddressMessageFilterTable ()
{
}
public TFilterData this [MessageFilter key] {
get { return dict [key]; }
set { dict [key] = value; }
}
public int Count {
get { return dict.Count; }
}
public bool IsReadOnly {
get { return false; }
}
public ICollection<MessageFilter> Keys {
get { return dict.Keys; }
}
public ICollection<TFilterData> Values {
get { return dict.Values; }
}
public void Add (KeyValuePair<MessageFilter,TFilterData> item)
{
dict.Add (item.Key, item.Value);
}
[MonoTODO]
public void Add (EndpointAddressMessageFilter filter, TFilterData data)
{
throw new NotImplementedException ();
}
public void Add (MessageFilter filter, TFilterData data)
{
dict.Add (filter, data);
}
public void Clear ()
{
dict.Clear ();
}
public bool Contains (KeyValuePair<MessageFilter,TFilterData> item)
{
return dict.ContainsKey (item.Key) &&
dict [item.Key].Equals (item.Value);
}
public bool ContainsKey (MessageFilter key)
{
return dict.ContainsKey (key);
}
public void CopyTo (KeyValuePair<MessageFilter,TFilterData> [] array, int index)
{
if (index < 0 || dict.Count >= array.Length - index)
throw new ArgumentOutOfRangeException ("index");
foreach (KeyValuePair<MessageFilter,TFilterData> item in dict)
array [index++] = item;
}
public IEnumerator<KeyValuePair<MessageFilter,TFilterData>> GetEnumerator ()
{
return dict.GetEnumerator ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
public bool GetMatchingFilter (Message message, out MessageFilter result)
{
throw new NotImplementedException ();
}
public bool GetMatchingFilter (MessageBuffer buffer, out MessageFilter result)
{
throw new NotImplementedException ();
}
public bool GetMatchingFilters (Message message, ICollection<MessageFilter> results)
{
throw new NotImplementedException ();
}
public bool GetMatchingFilters (MessageBuffer buffer, ICollection<MessageFilter> results)
{
throw new NotImplementedException ();
}
public bool GetMatchingValue (Message message, out TFilterData data)
{
throw new NotImplementedException ();
}
public bool GetMatchingValue (MessageBuffer buffer, out TFilterData data)
{
throw new NotImplementedException ();
}
public bool GetMatchingValues (Message message, ICollection<TFilterData> results)
{
throw new NotImplementedException ();
}
public bool GetMatchingValues (MessageBuffer buffer, ICollection<TFilterData> results)
{
throw new NotImplementedException ();
}
public bool Remove (KeyValuePair<MessageFilter,TFilterData> item)
{
if (dict.ContainsKey (item.Key) && dict [item.Key].Equals (item.Value)) {
dict.Remove (item.Key);
return true;
}
return false;
}
public bool Remove (EndpointAddressMessageFilter filter)
{
throw new NotImplementedException ();
}
public bool Remove (MessageFilter filter)
{
return dict.Remove (filter);
}
public bool TryGetValue (MessageFilter filter, out TFilterData filterData)
{
if (dict.ContainsKey (filter)) {
filterData = dict [filter];
return true;
} else {
filterData = default (TFilterData);
return false;
}
}
}
}

View File

@@ -0,0 +1,212 @@
//
// EndpointDispatcher.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2010 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.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Security.Tokens;
using System.Text;
namespace System.ServiceModel.Dispatcher
{
public class EndpointDispatcher
{
EndpointAddress address;
string contract_name, contract_ns;
ChannelDispatcher channel_dispatcher;
MessageFilter address_filter;
MessageFilter contract_filter;
int filter_priority;
DispatchRuntime dispatch_runtime;
// Umm, this API is ugly, since it or its members will
// anyways require ServiceEndpoint, those arguments are
// likely to be replaced by ServiceEndpoint (especially
// considering about possible EndpointAddress inconsistency).
public EndpointDispatcher (EndpointAddress address,
string contractName, string contractNamespace)
{
if (contractName == null)
throw new ArgumentNullException ("contractName");
if (contractNamespace == null)
throw new ArgumentNullException ("contractNamespace");
if (address == null)
throw new ArgumentNullException ("address");
this.address = address;
contract_name = contractName;
contract_ns = contractNamespace;
dispatch_runtime = new DispatchRuntime (this, null);
this.address_filter = new EndpointAddressMessageFilter (address);
}
public DispatchRuntime DispatchRuntime {
get { return dispatch_runtime; }
}
public string ContractName {
get { return contract_name; }
}
public string ContractNamespace {
get { return contract_ns; }
}
public ChannelDispatcher ChannelDispatcher {
get { return channel_dispatcher; }
internal set { channel_dispatcher = value; }
}
public MessageFilter AddressFilter {
get { return address_filter; }
set {
if (value == null)
throw new ArgumentNullException ("value");
address_filter = value;
}
}
public MessageFilter ContractFilter {
get { return contract_filter ?? (contract_filter = new MatchAllMessageFilter ()); }
set {
if (value == null)
throw new ArgumentNullException ("value");
contract_filter = value;
}
}
public EndpointAddress EndpointAddress {
get { return address; }
}
public int FilterPriority {
get { return filter_priority; }
set { filter_priority = value; }
}
#if NET_4_0
public bool IsSystemEndpoint { get; private set; }
#endif
internal void InitializeServiceEndpoint (bool isCallback, Type serviceType, ServiceEndpoint se)
{
#if NET_4_0
IsSystemEndpoint = se.IsSystemEndpoint;
#endif
this.ContractFilter = GetContractFilter (se.Contract, isCallback);
this.DispatchRuntime.Type = serviceType;
//Build the dispatch operations
DispatchRuntime db = this.DispatchRuntime;
if (!isCallback && se.Contract.CallbackContractType != null) {
var ccd = se.Contract;
db.CallbackClientRuntime.CallbackClientType = se.Contract.CallbackContractType;
db.CallbackClientRuntime.ContractClientType = se.Contract.ContractType;
ccd.FillClientOperations (db.CallbackClientRuntime, true);
}
foreach (OperationDescription od in se.Contract.Operations)
if (od.InCallbackContract == isCallback/* && !db.Operations.Contains (od.Name)*/)
PopulateDispatchOperation (db, od);
}
void PopulateDispatchOperation (DispatchRuntime db, OperationDescription od) {
string reqA = null, resA = null;
foreach (MessageDescription m in od.Messages) {
if (m.IsRequest)
reqA = m.Action;
else
resA = m.Action;
}
DispatchOperation o =
od.IsOneWay ?
new DispatchOperation (db, od.Name, reqA) :
new DispatchOperation (db, od.Name, reqA, resA);
o.IsTerminating = od.IsTerminating;
bool no_serialized_reply = od.IsOneWay;
foreach (MessageDescription md in od.Messages) {
if (md.IsRequest &&
md.Body.Parts.Count == 1 &&
md.Body.Parts [0].Type == typeof (Message))
o.DeserializeRequest = false;
if (!md.IsRequest &&
md.Body.ReturnValue != null) {
if (md.Body.ReturnValue.Type == typeof (Message))
o.SerializeReply = false;
else if (md.Body.ReturnValue.Type == typeof (void))
no_serialized_reply = true;
}
}
foreach (var fd in od.Faults)
o.FaultContractInfos.Add (new FaultContractInfo (fd.Action, fd.DetailType));
// Setup Invoker
o.Invoker = new DefaultOperationInvoker (od);
// Setup Formater
// FIXME: this seems to be null at initializing, and should be set after applying all behaviors.
// I leave this as is to not regress and it's cosmetic compatibility to fix.
// FIXME: pass correct isRpc, isEncoded
o.Formatter = new OperationFormatter (od, false, false);
if (o.Action == "*" && (o.IsOneWay || o.ReplyAction == "*")) {
//Signature : Message (Message)
// : void (Message)
//FIXME: void (IChannel)
if (!o.DeserializeRequest && (!o.SerializeReply || no_serialized_reply)) // what is this double-ish check for?
db.UnhandledDispatchOperation = o;
}
db.Operations.Add (o);
}
MessageFilter GetContractFilter (ContractDescription cd, bool isCallback)
{
List<string> actions = new List<string> ();
foreach (var od in cd.Operations) {
foreach (var md in od.Messages)
// For callback EndpointDispatcher (i.e. for duplex client), it should get "incoming" request for callback operations and "outgoing" response for non-callback operations.
// For non-callback EndpointDispatcher, it should get "outgoing" request for non-callback operations and "incoming" response for callback operations.
if ((od.InCallbackContract == isCallback) == md.IsRequest) {
if (md.Action == "*")
return new MatchAllMessageFilter ();
else
actions.Add (md.Action);
}
}
return new ActionMessageFilter (actions.ToArray ());
}
}
}

Some files were not shown because too many files have changed in this diff Show More