Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Client having problems recognizing ServiceKnownTypes?
    text
    copied!<p>How would I tell the WCF service what KnownTypes to use when passing data back to the client?</p> <p>I know I can use the <code>[ServiceKnownType]</code> attribute, which makes the service call run fine from a WCF Test Server, however it still fails from the client. Am I missing something here?</p> <pre><code>[OperationContract] [ServiceKnownType(typeof(SubClassA))] [ServiceKnownType(typeof(SubClassB))] BaseClassZ GetObject(); </code></pre> <p>Error message from client is:</p> <blockquote> <p>{"Element 'http://schemas.datacontract.org/2004/07/BaseClassZ' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/SubClassA'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'SubClassA' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer."}</p> </blockquote> <p>Serializing/Deserializing the object on the WCF server using a DataContractSerializer and a list of KnownTypes works fine.</p> <p><strong>UPDATE:</strong> It appears I can get the client to read the object correctly if I add KnownType attributes to the base class, but I am still looking for a way around this if possible since the base class is used for a lot of items and I don't want to have to modify the KnownType attributes on the base class anytime I add a new item.</p> <pre><code>[DataContract] [KnownType(typeof(SubClassA))] [KnownType(typeof(SubClassB))] public class BaseClassZ { ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload