Svcutil excludes the ServiceKnownType attribute from the generated proxy

I had a problem when I tried to implement the ServiceKnownType example from MSDN. In this example, they provide the following classes:

[DataContract()]
public class Widget
{
    [DataMember]
    public string Id;
    [DataMember]
    public string Catalog;
}

[DataContract()]
public class Machine : Widget
{
    [DataMember]
    public string Maker;
}

And the following interface:

[ServiceKnownType(typeof(Widget))]
[ServiceKnownType(typeof(Machine))]
[ServiceContract()]
public interface ICatalog
{
    [OperationContract]
    Hashtable GetItems();
}

, - ( " " /svcutil.exe) "ServiceKnownType" - ICatalog, " , :... , "" " , , , . , GetItems Hashtable , , ..

[OperationContract]
object GetItems();

[OperationContract]
Hashtable GetItems(object obj);

"ServiceKnownType" - ICatalog. - , ?

+5
3

, .

[KnownType(typeof(Machine))] Widget?

0

, , , . , AddGenericResolver IDesign ServiceModelEx.

: .NET 4.0, DataContractResolver

IDesign Downloads.

, , :

Client.AddGenericResolver( typeof ( K2Source ) );

, - !

" WCF: WCF Azure AppFabric" Juval Lowy

+1

The problem with ignoring ServiceKnownType by svcutil is still here. My solution adds "known types" to the client link with the software:

var client = new ServiceReferenceClient("clientEndpoint");
foreach (var o in client.Endpoint.Contract.Operations)
{
   o.KnownTypes.Add(typeof(MyType01));
   o.KnownTypes.Add(typeof(MyType02));
   o.KnownTypes.Add(typeof(MyType03));
}

This is not an ideal solution (should be hardcoded on the client side), but it works for me.

0
source

All Articles