Note that there are some explanatory texts on larger screens.

plurals
  1. POsvcutil omits the ServiceKnownType attribute from the generated interface proxy
    primarykey
    data
    text
    <p>I encountered a problem when I tried to implement the ServiceKnownType example from MSDN. In the example they provide the following classes:</p> <pre><code>[DataContract()] public class Widget { [DataMember] public string Id; [DataMember] public string Catalog; } [DataContract()] public class Machine : Widget { [DataMember] public string Maker; } </code></pre> <p>And the following interface:</p> <pre><code>[ServiceKnownType(typeof(Widget))] [ServiceKnownType(typeof(Machine))] [ServiceContract()] public interface ICatalog { [OperationContract] Hashtable GetItems(); } </code></pre> <p>The problem is that when the proxy class is generated (using “Add Service Reference” / svcutil.exe), the “ServiceKnownType” attributes are omitted from the ICatalog proxy interface, resulting in getting an exception “The formatter threw an exception while trying to deserialize the message: … Add the type corresponding to 'Widget' to the list of known types” To solve this problem I have to manually add the service known attributes to the generated proxy interface, which is a very bad solution, since the code regenerates when I update the reference. The interesting thing in all this situation, is that if the GetItems operation would return object instead of Hashtable, or getting an object as a parameter , then the problem would be solved, i.e.</p> <pre><code>[OperationContract] object GetItems(); </code></pre> <p>or</p> <pre><code>[OperationContract] Hashtable GetItems(object obj); </code></pre> <p>results in presence of the “ServiceKnownType” attribute on ICatalog proxy interface. Does anyone knows how to solve this problem?</p> <p>Thanks </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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