[英]Provide ServiceKnownType during runtime?
I've got a working WCF interface using more than 100 ServiceKnownType in the contract like this: 我在合同中使用了超过100个ServiceKnownType的WCF接口,如下所示:
[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 any way to provide these ServiceKnownTypes during runtime? 有没有办法在运行时提供这些ServiceKnownTypes?
It is not only error-prone and tedious to add all these ServiceKnownTypes in the source, it keeps my assemblies tied together in a way I don't like (I'd like to be able to extract these types into subassemblies to decouple them, but can't since the Service needs to list all the known types). 将所有这些ServiceKnownTypes添加到源代码中不仅容易出错且繁琐,它使我的程序集以我不喜欢的方式绑定在一起(我希望能够将这些类型提取到子组件中以将它们分离,但不能,因为服务需要列出所有已知的类型)。
Yes there is. 就在这里。
ServiceKnownTypeAttribute lets you specify a method name as the first parameter, followed by a parameter containing the System.Type implementing that method. ServiceKnownTypeAttribute允许您将方法名称指定为第一个参数,后跟包含实现该方法的System.Type的参数。
The specified method must be both static and public, and have a return type of IEnumerable. 指定的方法必须是static和public,并且返回类型为IEnumerable。
[ServiceKnownType("RegisterKnownTypes", typeof(Services))]
public class Services : IServices
{
static public IEnumerable<Type> RegisterKnownTypes(ICustomAttributeProvider provider)
{
}
}
see also http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx 另见http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.