Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 包含数组的params对象[]的OperationContract出现WCF序列化异常_C#_Arrays_Wcf_Serialization - Fatal编程技术网

C# 包含数组的params对象[]的OperationContract出现WCF序列化异常

C# 包含数组的params对象[]的OperationContract出现WCF序列化异常,c#,arrays,wcf,serialization,C#,Arrays,Wcf,Serialization,例如: 我的服务合同 [ServiceContract] public interface IProvider { [OperationContract] DataSet CreateDataSetFromSQL(string command, params object[] par); } 在其中一个参数是Array/List/ArrayList之前,任何东西都可以正常工作。 我得到一个序列化异常: data contract name 'ArrayOfanyType:htt

例如: 我的服务合同

[ServiceContract]
public interface IProvider
{
    [OperationContract]
    DataSet CreateDataSetFromSQL(string command, params object[] par);
}
在其中一个参数是Array/List/ArrayList之前,任何东西都可以正常工作。 我得到一个序列化异常:

data contract name 'ArrayOfanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.
正如我提到的,当字符串数组是一个参数时,我得到了相同的错误

客户

    private static ChannelFactory<IProvider> _channel;
    private static IProvider _proxy;
    private static DataTransferClient _client;

    public DataSet CreateDataSetFromSQL(string commandCode, params object[] par)
    { 
       return _proxy.CreateDataSetFromSQL(commandCode, par);
    }
private静态通道工厂\u通道;
私有静态IProvider\u代理;
私有静态数据传输客户端_客户端;
公共数据集CreateDataSetFromSQL(字符串命令代码,参数对象[]par)
{ 
返回_proxy.CreateDataSetFromSQL(命令代码,par);
}

你知道如何解决这个问题吗?

以防你没有读到错误信息:

将任何静态未知的类型添加到已知类型列表中-例如,使用属性或将它们添加到传递给DataContractSerializer的已知类型列表中

由于您的类型是“object”,所以任何“不仅仅是object”的内容都不是静态已知的,需要通过KnownType属性添加。如果要传递
列表
,则需要将类型为
列表
KnownType
属性放在服务的顶部

由于您没有发布服务,而只是发布接口,因此您也可以在接口上使用该属性:

[ServiceContract]
[ServiceKnownType(typeof(List<string>))] // <== this will enable the serializer to send and receive List<string> objects
public interface IProvider
{
    [OperationContract]
    DataSet CreateDataSetFromSQL(string command, params object[] par);
}
[服务合同]

[ServiceKnownType(typeof(List))]//生成客户端时?客户是什么?