Deperplexing WCF errors pt. 3 - Interfaces and KnownTypes
System.ServiceModel.CommunicationException
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error
This little gem was caused when calling a method on a service with an interface as a parameter, something like this:
[OperationContract]
void DoSomething (IMessage message)
When deserializing the IMessage, WCF had no way of knowing what type to deserialize it as, so it through the charming message above.
I don't know how this situation came to be, since the proxy generated by svcutil seems to create the message as DoSomething(object message) and not IMessage, but the principle should be the same.
The immediate solution that fixed this was adding the [KnownType(typeof(myMessage))] attribute to the method. This allows the deserialization engine to understand the message and do something constructive with it rather than crashing.
Naturally, I am less than pleased with this solution. The whole purpose of using interfaces is that I won't have to know, when coding, what objects will be passed to my service. I just want to expose the interface.
One way to keep this flexibility can be found in the very last paragraph of the long and detailed Data Contract Known Types article on MSDN - it seems that the list of Known Types can be defined globally in the system using the
3 Comments
Comments have been disabled for this content.
Single Kontakt aus Schleswig-Holstein said
The best things come in small packages.
herbs male enhancement said
Heads I win, Tails you lose.
Seerfrarben said
Ringlets reshape in length of life and place of growth. Longest-living fraction on his fore-part - to 4 or uniform 10 years, but the hair under the armpits, eyebrows and eyelashes - no greater than 3-4 months. Japanese old lady Hiroko Yamaske took 18 years to reach its braid measure of 2.6 m universal evolvement of whisker per date - there 0.35-0.4 mm, and at end of day they grow poorly, and preferably in the evening. On the headmaster, beard and underarm ringlets grows more actively than in the balance of the body.