0

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

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

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

客户端调用:

TransferProxy.PutTransferOnService(Transfer);

在服务上定义:

[OperationContract]
bool PutTransferOnService(TypeTransfer Transfer);

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

    [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; }
        }

    }
4

1 回答 1

3

You said - The whole class was copied from the client-side to the service-side.

You don't need to copy your class to server side. just define your class in a separate library and give reference of that same library to both client and server.

于 2013-01-29T03:00:38.133 回答