WCF通过对象参数传递整数数组

时间:2019-02-20 19:28:58

标签: c# wcf servicecontract

我正在尝试使用带有对象的方法调用通过WCF连接发送一个int数组。但是我收到此错误

'System.ServiceModel.CommunicationException' in mscorlib.dll ("There was an error while trying to serialize parameter http://tempuri.org/:Data. The InnerException message was 'Type 'System.Object[]' with data contract name 'ArrayOfanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types.

这是我的界面

<ServiceContract()>
Public Interface myServiceContract
    <OperationContract(IsOneWay:=True)>
    Sub DoStuff(ByVal str As String, ByVal Data As Object)
End Interface

这是我使用界面的方式

Dim data(2) As Object
data(0) = 20
data(1) = 22
data(2) = 255
remoteContext.DoStuff("Hello", data) ' this line throws the exception

如何在不引发异常的情况下通过wcf连接发送数据数组?

这是公开的,因此更改参数类型会给我带来很多麻烦。

0 个答案:

没有答案