返回字节数组

时间:2011-05-11 22:35:09

标签: vb.net arrays wcf byte

我有以下功能(在WCF中)

Public Function GetPDF_Byte() As Byte Implements IService1.GetPDF_Byte
    Dim fs As New FileStream("C:\My.pdf", FileMode.Open, FileAccess.Read)

    Dim ImageData As Byte() = New Byte(fs.Length - 1) {}

    fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length))

    fs.Close()

    Return ImageData


End Function

问题是,我在'Return ImageData'上收到以下错误:

Value of type '1-dimensional array of Byte' cannot be converted to 'Byte'.

我一直在玩它,但似乎无法弄清楚我需要对ImageData做些什么。

1 个答案:

答案 0 :(得分:1)

函数需要返回字节数组:

Public Function GetPDF_Byte() As Byte()

因此,接口和类中的方法被定义为Byte并且需要更改为字节数组,或者它必须确实是字节,并且您需要返回单个字节 - 我真的怀疑它是因为它是图像数据。