Provide ServiceKnownType at runtime?

I have a working WCF interface using over 100 ServiceKnownType in a contract as follows:

[ServiceKnownType(typeof(RowUser))]
[ServiceKnownType(typeof(RowRegion))]
[ServiceKnownType(typeof(RowDocument))]
[... loads more ...]
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IServiceBrowse : IDisposable
{
  [OperationContract]
  void Insert(Row satz);
}

Is there a way to provide these ServiceKnownTypes at runtime?
Not only is it error-prone and tedious to add all of these ServiceKnownTypes to the source code, it keeps my assemblies in a connection in a way that I don't like (I would like to be able to extract these types into nodes to decouple them, but cannot, because the service needs to list all known types).

+3
source share
1 answer

Yes there is.

ServiceKnownTypeAttribute , , System.Type, .

, IEnumerable.

[ServiceKnownType("RegisterKnownTypes", typeof(Services))]
public class Services : IServices
{
    static public IEnumerable<Type> RegisterKnownTypes(ICustomAttributeProvider provider)
    {
    }
}

. http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx

+10

Source: https://habr.com/ru/post/1750083/


All Articles