0

This is my Client class

using System;
using System.Data;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace Main.Communication
{
    public delegate void EventReceivedEventHandler(DataSet InBoxNotifications, bool updateOutBoxFlag);
    public delegate void OpenConnectEventHandler(int spaceId, string accessionNumber, string modality, long assignedCaseId, long originalCaseId);
    [DataContract]
    public class ClientClass : IClient, IDisposable
    {
        public event EventReceivedEventHandler EventReceived;
        public event OpenConnectEventHandler OpenConnectSystem;

        public ClientClass(int userId)
        {
            this.UserId = userId;
            this.Authentication = Guid.NewGuid().ToString();
        }

        private string _authentication;
        [DataMember]
        public string Authentication
        {
            get { return _authentication; }
            set { _authentication = value; }
        }

        private int _userId;
        [DataMember]
        public int UserId
        {
            set { _userId = value; }
            get { return _userId; }
        }

        #region "IClient Members"
        public bool UpdateInDataBox(DataSet InBoxNotifications, bool updateOutBoxFlag)
        {
            if (EventReceived != null) EventReceived(InBoxNotifications, updateOutBoxFlag);
            return true;
        }
        public void OpenReviewPanel(int spaceId, string accessionNumber, string modality, long assignedCaseId, long originalCaseId)
        {
            if (OpenConnectSystem != null) OpenConnectSystem(spaceId, accessionNumber, modality, assignedCaseId, originalCaseId);
        }
        #endregion

        #region IDisposable Members
        public void Dispose()
        {
            ((ICommunicationObject)this).Abort();
        }
        #endregion
    }
}

Where IClient is the Callback. I am using netTcp binding. While Passing this object to the Server method, I am getting a error like this,

There was an error while trying to serialize parameter http://tempuri.org/:observer. The InnerException message was 'Type 'Main.Communication.ClientClass' with data contract name 'CommunicationClient:http://schemas.datacontract.org/2004/07/Main.Communication.ClientClass' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

Sreekumar P
  • 5,900
  • 11
  • 57
  • 82
  • 2
    Are you sure you can decorate the same class with ServiceContract and DataContract attributes? Maybe you can; but I never have. – Dave Lawrence Jul 10 '12 at 14:20
  • I agree... you ought to have 2 different classes: one is your service class, the other one is your data class. Service manipulates data – Kek Jul 10 '12 at 14:22
  • Also if you change your implementation, all those consuming it dont need to update their references as they're consuming the contract. Anyway - thats by the wayside here. – Chris Jul 10 '12 at 14:29
  • I guess it.. :) ... let me try – Sreekumar P Jul 10 '12 at 14:29
  • 2
    First of all you are doing WAY too much in the class. Your data contracts should only consist of properties. None of your IClient code will serialize across the wire. Secondly you cannot have a Service contract contain a DataContract. Your service contract is your interface and IClient should be inherited by your service you are deploying. Finally your Dispose implementation calling abort is not exactly disposing a resource. – SASS_Shooter Jul 10 '12 at 15:41

0 Answers0