0

In the client application, I input an item id, and the WCF server is supposed to return an object of type ItemDTO. However, when the reply is made, the object is empty.

ItemDTO itm = Connection.Instance.HttpProxy.GetItem(ItemID);

What I can confirm so far:

  • The item requested is successfully taken from the database
  • The mapping did work (checked the contents of the resulting mapping)
  • The contents was indeed sent (checked using Fiddler) enter image description here

  • However, when I check the contents of itm, it's empty.

This is the GetItem() method in the WCF Server:

public ItemDTO GetItem(string itemID) {
    using (var db = new PoSEntities()) {
        var query = from i in db.Items
                    where i.ItemID.Equals(itemID)
                    select i;
        Item item = query.FirstOrDefault();
        return item == null ? null : Mapping.Map<Item, ItemDTO>(item);
    }
}

I use AutoMapper to map the entity object to the DTO:

    public static H Map<T, H>(T i) {
        Mapper.CreateMap<T, H>();
        return Mapper.Map<T, H>(i);
    }

The Item class is generated by Entity Framework:

public partial class Item
{
    public Item()
    {
        this.Sal1 = new HashSet<Sal1>();
    }

    public string ItemID { get; set; }
    public string Name { get; set; }
    public string Manufacturer { get; set; }
    public int StockQuantity { get; set; }
    public decimal Price { get; set; }

    public virtual ICollection<Sal1> Sal1 { get; set; }
}

Connection class:

 public sealed class Connection {

    private readonly string _address = "http://Edwin:8080/PoS";
    private static Connection _instance;
    private static object _padLock = new Object();
    private static ChannelFactory<IPoS> httpFactory;

    private static IPoS _httpProxy; //Singleton
    public IPoS HttpProxy { get { return _httpProxy; } }

    public static Connection Instance {
        get {
            if (_instance == null) {
                lock (_padLock) {
                    if (_instance == null) {
                        _instance = new Connection();
                    }

                }
            }
            return _instance;
        }
    }

    private Connection() {
        httpFactory = new ChannelFactory<IPoS>(
            new BasicHttpBinding(), 
            new EndpointAddress(_address));
        _httpProxy = httpFactory.CreateChannel();
    }
}

ItemDTO Class:

[DataContract]
public class ItemDTO {
    [DataMember]
    public string ItemID { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string Manufacturer { get; set; }
    [DataMember]
    public int StockQuantity { get; set; }
    [DataMember]
    public decimal Price { get; set; }
}
1
  • To me, that suggests an error occurred on the host side but now exception or web fault was returned to you. You might try using Fiddler to debug the communication. Sometimes Fiddler will pick up error messages your client can't. Also, turn on the logging on the host side and check for errors.
    – Brian
    Commented Jun 13, 2013 at 11:34

1 Answer 1

0

Finally fixed it, the solution is very simple.

Simply give the DTO class (in this case, ItemDTO) a namespace on both end.
i.e: [DataContract] to [DataContract(Namespace"PoSDTO")]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.