开发者

Passing DTO's from a seperate Project to UI Layer WCF RIA services

I have a solution that I have designed with 5 layers.

They are:

  • UI/Presentation Layer
  • Service Layer
  • Business Logic Layer
  • Data Access Layer
  • DTO/Common Layer (IQUTECHDTO)

I want to pass the DTO to the UI. Below is the service layer that exposes a method GetVendors which I want to return the VendorDTO. This object will populate a drop down box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using IQUTechDTO;
usi开发者_开发知识库ng IQUTECHDAL;

namespace BusinessApplication6.Web.Services
{

    public class Foos
    {

        [Key]

        public int FooId { get; set; }

        public string Name { get; set; }

    }

    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class BillService : DomainService
    {

        public IEnumerable<Foos> GetFoos()
        {
            return new List<Foos> { new Foos { FooId = 42, Name = "Fred" } };
        }

        [Query]
        public IEnumerable<VendorDTO> GetVendors()
        {
            return new List<VendorDTO> { new VendorDTO { VendorID = 42 } };  
        }

    }
}

On the UI .cs file when I try and create an object of type VendorDTO I cannot. I was however able to access the Foo object from the UI Layer.

The VendorDTO was marked as serialazble but it does however reside in a seperate project (IQUTECHDTO)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.ServiceModel.DomainServices;
using System.ServiceModel.Web;


namespace IQUTechDTO
{
    public enum LoadStatus
    {
     Initialized = 0,
     Ghost = 1,
     Loaded = 2
    }

    [Serializable]
    public class VendorDTO
    {
        /// <summary>
        ///DTO for the 'Vendor' object.
        /// </summary>

        public VendorDTO()
        {
            this.loadStatus = LoadStatus.Initialized;
        }

        ///<summary>
        /// Copy constructor
        ///</summary>
        public VendorDTO(VendorDTO sourceDTO)
        {
            loadStatus = sourceDTO.loadStatus;
            VendorID = sourceDTO.VendorID;
            VendorName = sourceDTO.VendorName;
            VendorAddress1 = sourceDTO.VendorAddress1;
            VendorAddress2 = sourceDTO.VendorAddress2;
            VendorCity = sourceDTO.VendorCity;
            VendorState = sourceDTO.VendorState;
            VendorEmail = sourceDTO.VendorEmail;
            VendorPhone = sourceDTO.VendorPhone;
            VendorPOC = sourceDTO.VendorPOC;
            VendorRegion = sourceDTO.VendorRegion;
        }

        public LoadStatus loadStatus;

        [Key]
        public int VendorID { get; set; }
        public string VendorName;
        private string VendorAddress1;
        private string VendorAddress2;
        private string VendorEmail;
        private string VendorPhone;
        private string VendorCity;
        private string VendorState;
        private string VendorPOC;
        private string VendorRegion;

    }
}

Below is the UI Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using BusinessApplication6.Web.Services;
using System.ServiceModel.DomainServices.Client;
using BusinessApplication6.Web;


namespace BusinessApplication6.Views.BOM
{
    public partial class BOMCRUD : Page
    {
        public BOMCRUD()
        {
            InitializeComponent();
            LoadTree();


        }

        public void LoadTree()
        {
            BillContext newCon = new BillContext();


            //This works
            Foos fooobj = new Foos();

            //This doesnt work
            VendorDTO vendorobj = new VendorDTO();

        }



        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }



    }
}

Why will it not let me access this object.

Your help would be greatly appreciated.

Regards, Tom


The UI class has doesn't have a reference to IQUTECHDTO like the Foos class does(in BusinessApplication6.Web).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜