0

I am using a combination of WCF and SignalR for a project I am working on.

The WCF service has a number of DTOs that it brings over just fine because they are part of an [OperationContract] (either as a parameter or return type).

However, I have two classes (MachineStatusDto and DeviceStatusDto) that are only used as return types for broadcasts from the server via SignalR:

machine.On<MachineStatusDto>("Update", m => UpdateMachineRecord(m)); //On client side

I could obviously just make a method on my WCF service that uses these types but I feel like there should be a way to inform the WCF service to include specific types, even if they aren't part of an [OperationContract].

EDIT:

In the end, if you just add [ServiceKnownType(typeof(SomeDto))] to your WCF ServiceContract interface, it'll know to send over those classes in addition to the ones that are explicitly used in the Service Contract. Simple as that.

Killnine
  • 5,728
  • 8
  • 39
  • 66
  • 2
    Usually I'd just separate those classes into a separate shared "domain" project so all projects have the same view of the class and not what has been referenced by the wcf service. – cillierscharl Oct 03 '13 at 16:19
  • The classes already are all in a shared 'domain' project in the service solution (and thereby would be there if I imported a DLL rather than used a service reference). I just wanted to avoid having to pass around a DLL when I could instead just update a service reference. – Killnine Oct 03 '13 at 16:22
  • In my experience you have to attach it to an [OperationContract] in order for it to show up on your client side. I have tried multiple work arounds, but in the end this is what I always do. – Daryl Behrens Oct 03 '13 at 16:23
  • 1
    In my opinion i'd much rather have my types in a dll than rely on them being available through a service reference. This way you never need to update your service reference when you change anything in your DTO and you have one source of what the object looks like, not two. – cillierscharl Oct 03 '13 at 16:25
  • WCF allows for data contract versioning to get around this and I see updating a service reference as much less error-prone than passing around a specific version of a DLL, especially when multiple teams are involved with their own separate apps. I guess this is just one of the shortcomings of SignalR in a fat application – Killnine Oct 03 '13 at 16:33
  • http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx – ta.speot.is Oct 03 '13 at 22:13

1 Answers1

1

This was discussed many times for ex. here and here.

Community
  • 1
  • 1
SalientBrain
  • 2,431
  • 16
  • 18
  • I searched for a solution but these all revolve around `ServiceKnownType` (not exactly the most intuitive search term). I am going to edit my original question to be more clear about the solution that worked for me. – Killnine Oct 04 '13 at 12:42