如何在客户端上使用与服务相同的类?

时间:2013-01-29 02:42:00

标签: c# .net wcf

如何通过WCF服务传递整个定义的类?我在服务和客户端都定义了类。我一直收到错误:

  

最佳重载方法匹配有一些无效的参数。

整个班级从客户端复制到服务端。

客户端呼叫:

TransferProxy.PutTransferOnService(Transfer);

定义服务:

[OperationContract]
bool PutTransferOnService(TypeTransfer Transfer);

我不想从客户端访问类中的单个项目,我只想移动WHOLE 填充对象并在服务器端进行处理。

    [DataContract]
    public class TypeTransfer
    {

        private string userID;
        private string transferNum;
        private DateTime effectiveDate;
        private int unitCount;
        private int skuCount;
        private string reason;
        private string localStatus;
        private string destStatus;
        private string carrier;
        private string sourceStore;
        private string destinationStore;
        private string inSeal;
        private string outSeal;

        [DataMember]
        private List<TypeSOQ> correspondingSOQ = new List<TypeSOQ>();

        [DataMember]
        private List<TypeProductList> ProductList = new List<TypeProductList>();


        public TypeTransfer() { }

        // Function adds single item to transfer object
        public void AddItem(int ProductID, string SKU, string PrimarySKU, string SCC, string ProductDescription, int TransferQty)
        {
            ProductList.Add(new TypeProductList
            {
                productID = ProductID,
                sku = SKU,
                primaryUPC = PrimarySKU,
                scc = SCC,
                description = ProductDescription,
                transferQty = TransferQty
            });
        }

        // Add SOQ to transfer object (can support multiple SOQ's)        
        public void AddSOQ(TypeSOQ soq)
        {
            correspondingSOQ.Add(soq);
        }

        // Function returns number of skus in Product List        
        public int GetSKUTotal()
        {
            return ProductList.Count();
        }

        // Function returns total number of items in transfer
        public int GetItemTotal()
        {
            int itemtotal = 0;
            for (int i = 0; i < ProductList.Count(); i++)
            {
                itemtotal += ProductList[i].transferQty;
            }
            return itemtotal;

        }

        // Return entire SOQ list        
        public List<TypeSOQ> GetSOQs()
        {
            return correspondingSOQ;
        }

        // Returns full product list in transfer object        
        public List<TypeProductList> GetProductList()
        {
            return ProductList;
        }

        [DataMember]
        public string UserID
        {
            get { return userID; }
            set { userID = value; }
        }
        [DataMember]
        public string TransferNum
        {
            get { return transferNum; }
            set { transferNum = value; }
        }
        [DataMember]
        public DateTime EffectiveDate
        {
            get { return effectiveDate; }
            set { effectiveDate = value; }
        }
        [DataMember]
        public int UnitCount
        {
            get { return unitCount; }
            set { unitCount = value; }
        }
        [DataMember]
        public string Reason
        {
            get { return reason; }
            set { reason = value; }
        }
        [DataMember]
        public string LocalStatus
        {
            get { return localStatus; }
            set { localStatus = value; }
        }
        [DataMember]
        public string DestStatus
        {
            get { return destStatus; }
            set { destStatus = value; }
        }
        [DataMember]
        public string Carrier
        {
            get { return carrier; }
            set { carrier = value; }
        }
        [DataMember]
        public string SourceStore
        {
            get { return sourceStore; }
            set { sourceStore = value; }
        }
        [DataMember]
        public string DestStore
        {
            get { return destinationStore; }
            set { destinationStore = value; }
        }
        [DataMember]
        public string InSeal
        {
            get { return inSeal; }
            set { inSeal = value; }
        }
        [DataMember]
        public string OutSeal
        {
            get { return outSeal; }
            set { outSeal = value; }
        }
        [DataMember]
        public int SKUCount
        {
            get { return skuCount; }
            set { skuCount = value; }
        }

    }

1 个答案:

答案 0 :(得分:3)

你说 - The whole class was copied from the client-side to the service-side

您无需将班级复制到服务器端。只需在单独的库中定义您的类,并将相同的库引用到客户端和服务器。