我在客户端有一个函数,获取文件,从它做一个字节数组,并将该数组发送到服务器上的web服务!这是客户端的函数:
Public Function GetFile(ByVal filename As String) As Byte()
Dim binReader As New BinaryReader(File.Open(filename, FileMode.Open))
binReader.BaseStream.Position = 0
Dim binFile As Byte() = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length))
binReader.Close()
Return binFile
End Function现在asmx webservice在服务器上,得到字节数组,并将字节数组转换为需要保存在服务器上的文件。这是webservice中需要执行此操作的函数:
<WebMethod()> _
Public Sub PutFile(ByVal buffer As Byte(), ByVal filename As String)
Dim binWriter As New BinaryWriter(File.Create((filename), FileMode.CreateNew, FileAccess.ReadWrite))
binWriter.Write(buffer)
binWriter.Close()
End Sub在我调用这个webservice之后,我得到了这个错误:
Server was unable to process request. ---> System.ArgumentOutOfRangeException: Enum value was out of legal range. Parameter name: options at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)服务器上需要保存文件的路径是D:\Archive我设置了此文件夹的权限,并赋予aspnet用户对此文件夹的完全控制权限,但即使在此之后,我仍收到相同的错误!
发布于 2010-10-21 15:28:00
我可能会使用ReadAllBytes和WriteAllBytes来简化这两个函数
Public Function GetFile(ByVal filename As String) As Byte()
Return File.ReadAllBytes(filename)
End Function在服务器上:
<WebMethod()> _
Public Sub PutFile(ByVal buffer As Byte(), ByVal filename As String)
File.WriteAllBytes(filename, buffer)
End Subhttps://stackoverflow.com/questions/3985142
复制相似问题