1

当 WCF 服务器实现 ServiceKnownType 时,如何在客户端检索未知类型的合同?

造成问题的类型不会返回或用作参数。我在我的服务器上集成了 GetKnowTypes(),如下所示:WCF Problem Sending Object To Client

[ServiceKnownType("GetKnownTypes", typeof(KnownTypesProvider))]
public interface ITestCallback
{
    //What I liked to do:
    [OperationContract(IsOneWay = true)]
    void TestPropertyChanged<T>(string propertyName, Type propertyType, T propertyValue);

    //What I think is required:
    [OperationContract(IsOneWay = true)]
    void TestSerializedPropertyChanged(string propertyName, string propertyType, string serializedPropertyValue);
}

显然我们不能使用 T 型。所以我序列化了我的属性,我想在我的客户端反序列化,但为此我需要原始类型。

我想在客户端获得类似这样的类型:

/// <summary>
/// Get custom types from server
/// </summary>    
private Type GetPropertyType(string typeName)
{
    try
    {
        var types = KnownTypesProvider.GetKnownTypes(); //ERROR : The name 'KnownTypesProvider' does not exist in current context
        foreach (var knownType in types)
        {
            if (knownType != null && knownType.FullName == typeName)
                return knownType;
        }
    }
    catch (Exception)
    {
    }
}

可能吗 ?如何 ?

4

0 回答 0