3

Edit: Please note my question is different from the one shown by the editor. I have no problem sending an IEnumerable or IDictionary in general but I have issues with sending them, containing interfaces.

I wonder whether ServiceStack has problems serializing or transferring IEnumerables of interfaces? Actions that return other objects such as DTOs or strings do not cause any problems but when I try to return IEnumerable<IWhateverInterface> then an empty enumerable arrives on the client end. I verified that the enumerable is containing desired elements right before the Action within the Service returns them thus the only issue I see is with the serialization or sending part.

I made sure to reference the interface in all concerned classes.

Anyone who could shed light into this?

Thanks

Matt
  • 7,004
  • 11
  • 71
  • 117
  • Why are you returning interfaces in the first place? you should never mock your models. – mythz May 29 '13 at 03:56
  • @mythz, could you elaborate please? How is mapping everything into new response DTOs more desirable? The interface is an IPluginAttributeView which I use in combination with MEF. Any hints at how to improve this and why it is better than what I currently do? I want to learn and can openly admit I am new to this, I am not a web programmer and thus do not deal with Views, Models, and ViewModels. – Matt May 29 '13 at 04:48
  • @myrthz, and why returning an IDictionary works just fine? After all it is also an interface and I feel there is solid justification for sending around interfaces of collections. – Matt May 29 '13 at 04:55
  • To those who voted to close, this question is different, I am not having a problem with sending an interface such as IEnumerable or IDictionary, but a collection that contains interfaces such as IPluginAttributeView (MEF). – Matt May 29 '13 at 04:56
  • You haven't provided any context about your issue so we can't verify what it is but returning interfaces in a service layer is simply bad practice, clients/serializers have no idea what concrete impl to hydrate it back into and interfaces are primarily used when you have multiple concrete impls or you want to substitute behavior, which you shouldn't be doing for models. I recommend returning the concrete POCOs or [use purpose-specific DTOs](http://stackoverflow.com/a/15369736). – mythz May 29 '13 at 05:39
  • @mythz, thanks, what you explained makes sense, I built full DTOs to communicate back and forth rather than forward interfaces. Thanks – Matt Jun 14 '13 at 06:15

1 Answers1

1

I would defer to ServiceStack authors to confirm this, but I believe the serializers use reflection to produce values for transport. Since you're using an interface there is nothing to reflect.

Dmitry
  • 1,513
  • 1
  • 15
  • 33