none
Returning an Array of DataContract Object- ActionNotSupportedException RRS feed

  • Question

  • I'm trying to call a service that return an array of class objects which is marked as DataContract, but it generates an error, following are my classes which described in brief

    what i'm trying is to return a contract object as following to client:

        [DataContract]
        public class CpuInfo
        {
            private string _cpuId;
            private double _load;
    
            public CpuInfo(string cpuId, double load)
            {
                _cpuId = cpuId;
                _load = load;
            }
    
            [DataMember]
            public double Load
            {
                get { return _load; }
                set { _load = value; }
            }
    
            [DataMember]
            public string CpuId
            {
                get { return _cpuId; }
                set { _cpuId = value; }
            }
        }

    for this i have several interfaces and classes, and manual configuration...

    my Main interface:

    [ServiceContract] public interface IAllServices: IServiceController, IServerStatus { }

     One Of My Service Interface I'm Targeting

    [ServiceContract]
        public interface IServerStatus
        {
            [OperationContract]
            CpuInfo[] GetCpuUsage();
        }

    Another service i dont care for now

    [ServiceContract] public interface IServiceController {

    //...

    }

    And here is my proxy which act both in server and client

    public class Proxy { private readonly BasicHttpBinding _binding = new BasicHttpBinding(BasicHttpSecurityMode.None); public IServiceController CMessenger = null; public IServerStatus ServerStatusMessage = null; public Proxy() { EndpointAddress endpointAddress = new Toolkit(_binding).ConfigChannel(); //First Modify BasicBinding Inside Class, Then pass it to ChannelFactory var services = new ChannelFactory<IAllServices>(_binding).CreateChannel(endpointAddress); CMessenger = services; ServerStatusMessage = services; } }

    public class Toolkit
        {
            readonly BasicHttpBinding _binding;

            public Toolkit(BasicHttpBinding binding)
            {
                _binding = binding;
            }



            public EndpointAddress ConfigChannel()
            {

                string uri = string.Empty;

                uri = (ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerServerUrl") +
                              "/ServerController");

                var endpointAddress = new EndpointAddress(uri);

                var quotas = new XmlDictionaryReaderQuotas
                {
                    MaxDepth =
                        Convert.ToInt32(ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxDepth")),
                    MaxStringContentLength =
                        Convert.ToInt32(
                            ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxStringContentLength")),
                    MaxArrayLength =
                        Convert.ToInt32(
                            ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxArrayLength")),
                    MaxBytesPerRead =
                        Convert.ToInt32(
                            ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxBytesPerRead")),
                    MaxNameTableCharCount =
                        Convert.ToInt32(
                            ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxNameTableCharCount"))
                };

                _binding.ReaderQuotas = quotas;
                _binding.MaxBufferPoolSize =
                    Convert.ToInt64(ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxBufferPoolSize"));
                _binding.MaxReceivedMessageSize =
                    Convert.ToInt64(ServerControllerDatabaseReader.GetGeneralSettingValue2("ServerControllerMaxReceivedMessageSize"));
                _binding.MessageEncoding = WSMessageEncoding.Text;
                _binding.TextEncoding = Encoding.UTF8;
                return endpointAddress;
            }
        }

    So these create my WCF DLL,

    then i use my service like:

    first i generate my implementation of IAllServices service class

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Threading;
    using Faradid.Service.ClientProxy.Contracts;
    using Faradid.Service.ClientProxy.Model;
    using Utility.Services;
    
    namespace Faradid.Service.ServerController
    {
        class AllServices:IAllServices
        {
            static readonly EventLog EventLogger = new EventLog();
    
            static AllServices()
            {
                EventLogger.Source = "FaradidServiceController";
                EventLogger.Log = "Faradid";
    
                try
                {
                    //_eventLogger.Clear();
                    //EventLog.DeleteEventSource(this._eventLogger.Source);
    
                    ((ISupportInitialize)(EventLogger)).BeginInit();
                    if (!EventLog.SourceExists(EventLogger.Source))
                    {
                        EventLog.CreateEventSource(EventLogger.Source, EventLogger.Log);
                    }
                    ((ISupportInitialize)(EventLogger)).EndInit();
                }
                catch (Exception ex)
                {
                    EventLogger.WriteEntry(ex.Message,EventLogEntryType.Warning);
                    //If cant create log, let it continue but then create log file manually
                }
            }
    
    //Lots OF CODE HERE
    
            public CpuInfo[] GetCpuUsage()
            {
                List<CpuInfo> cpuInfos = new List<CpuInfo>();
                var cat = new PerformanceCounterCategory("Processor");
                var instances = cat.GetInstanceNames();
    
                List<PerformanceCounter> pcs = new List<PerformanceCounter>();
    
                foreach (var s in instances)
                {
                    var pcX = new PerformanceCounter("Processor", "% Processor Time");
                    pcs.Add(pcX);
                    pcX.InstanceName = s;
                    pcX.NextValue();
                }
    
                Thread.Sleep(1000);
    
                foreach (var pc in pcs)
                {
                    cpuInfos.Add(new CpuInfo(pc.InstanceName, pc.NextValue()));
                }
    
                return cpuInfos.ToArray();
            }
        }
    }

    And my host class

    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.ServiceModel;
    using System.Threading;
    using Faradid.Service.ClientProxy;
    using Faradid.Service.ClientProxy.Contracts;
    
    namespace Faradid.Service.ServerController
    {
        public static class Host
        {
            private static readonly BasicHttpBinding Binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            private static ServiceHost _mHost;
    
            static readonly EventLog EventLogger = new EventLog();
    
    
            public static void Start()
            {
                  //UNRELATED CODE HERE
                  TryStart()
            }
    
    //Other Methods in here
    
            private static bool TryStart()
            {
    
                    EndpointAddress endpointAddress = new Toolkit(Binding).ConfigChannel();
    
                    _mHost = new ServiceHost(typeof (AllServices), endpointAddress.Uri);
                    _mHost.AddServiceEndpoint(typeof (IAllServices), Binding, "");
    
                    _mHost.Open();
            }
        }
    }

    and i run my service

     protected override void OnStart(string[] args)
            {
                Host.Start();
            }
    The message with Action 'http://tempuri.org/IServerStatus/GetCpuUsage' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

     

    i think the issue is with the returning of a class object as array, or maybe with the basic binding, any way can any one help me in here?

    this is an example of how i use the method in my client:

    //Inside Class
    private readonly ServerControllerProxy _serverControllerProxy;
    
    public frmServiceController()
            {
                _serverControllerProxy = new ServerControllerProxy(); //Preload and Set factory
    
            }
    
    private void button1_Click(object sender, EventArgs e)
            {
                    CpuInfo[] cpuUsage = _serverControllerProxy.ServerStatusMessage.GetCpuUsage();
                    MessageBox.Show(cpuUsage[0].Load.ToString());
            }



    • Edited by deadManN Wednesday, August 27, 2014 3:54 AM
    Tuesday, August 26, 2014 6:23 AM

Answers

  • Hi,

    About this error messages, a "ContractFilter mismatch at the EndpointDispatcher" means the receiver could not process the message because it did not match any of the contracts the receiver has configured for the endpoint which received the message.

    This may due to:

    • You have different contracts between client and sender.
    • You're using a different binding between client and sender.
    • The message security settings are not consistent between client and sender.

    You could try to update the webservice reference on the project. Besides, for more information you could refer to:

    http://stackoverflow.com/questions/5487791/wcf-contractfilter-mismatch-at-the-endpointdispatcher-exception

    Regards

    • Marked as answer by deadManN Saturday, August 30, 2014 6:18 AM
    Wednesday, August 27, 2014 7:42 AM
    Moderator

All replies

  • -just make my post come it top again-
    Wednesday, August 27, 2014 4:02 AM
  • Hi,

    About this error messages, a "ContractFilter mismatch at the EndpointDispatcher" means the receiver could not process the message because it did not match any of the contracts the receiver has configured for the endpoint which received the message.

    This may due to:

    • You have different contracts between client and sender.
    • You're using a different binding between client and sender.
    • The message security settings are not consistent between client and sender.

    You could try to update the webservice reference on the project. Besides, for more information you could refer to:

    http://stackoverflow.com/questions/5487791/wcf-contractfilter-mismatch-at-the-endpointdispatcher-exception

    Regards

    • Marked as answer by deadManN Saturday, August 30, 2014 6:18 AM
    Wednesday, August 27, 2014 7:42 AM
    Moderator
  • I'll just toss my $.02 in here. You can use auto properties, which the complier makes the private backing variable.

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    public class CpuInfo
       
    {
           
    private string _cpuId;
           
    private double _load; public CpuInfo(string cpuId, double load)
           
    {
                _cpuId
    = cpuId;
                _load
    = load;
           
    }

           
    [DataMember]
           
    public double Load
           
    {
               
    get { return _load; }
               
    set { _load = value; }
           
    }

           
    [DataMember]
           
    public string CpuId
           
    {
               
    get { return _cpuId; }
               
    set { _cpuId = value; }
           
    }
       
    }

    Wednesday, August 27, 2014 6:56 PM
  • Hi,

    About this error messages, a "ContractFilter mismatch at the EndpointDispatcher" means the receiver could not process the message because it did not match any of the contracts the receiver has configured for the endpoint which received the message.

    This may due to:

    • You have different contracts between client and sender.
    • You're using a different binding between client and sender.
    • The message security settings are not consistent between client and sender.

    You could try to update the webservice reference on the project. Besides, for more information you could refer to:

    http://stackoverflow.com/questions/5487791/wcf-contractfilter-mismatch-at-the-endpointdispatcher-exception

    Regards

    no different contract... both client and server created through Proxy class, which mean all configuration are the same...

    and that mean that also binding is same too

    i'm using

    new BasicHttpBinding(BasicHttpSecurityMode.None)

    so i think there shouldn't be any security regarding things that deny me...

    Saturday, August 30, 2014 3:47 AM
  • I'll just toss my $.02 in here. You can use auto properties, which the complier makes the private backing variable.

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    public class CpuInfo
       
    {
           
    private string _cpuId;
           
    private double _load; public CpuInfo(string cpuId, double load)
           
    {
                _cpuId
    = cpuId;
                _load
    = load;
           
    }

           
    [DataMember]
           
    public double Load
           
    {
               
    get { return _load; }
               
    set { _load = value; }
           
    }

           
    [DataMember]
           
    public string CpuId
           
    {
               
    get { return _cpuId; }
               
    set { _cpuId = value; }
           
    }
       
    }


    thank you, i'll try that, i also test to add default constructor and also remove both, but didn't test that one...
    Saturday, August 30, 2014 3:48 AM
  • As i explore the link, i found my answer, ...

    [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
    class AllServices:IAllService

    after putting this attribute my issue solved

    Saturday, August 30, 2014 6:19 AM