需要专家帮助 [英] Expert help needed
问题描述
您好,
我们有一些间歇性工作的代码(见下文)
我想知道是否有人有更好的方法或者关于为什么我们这些错误的想法。这部分代码基本上得到一个文件并将它从有线或DSL连接上传到我们的t1线路到服务器。文件大小
的范围从1.7 MB到4 MB,可能有1-40个文件需要上传到我们的服务器。我们也可能有多台笔记本电脑同时从不同的位置运行这个
应用程序。尝试存储文件
的文件夹让每个人都拥有完全权限。任何帮助都会非常感激。
前端vb应用程序代码:
私函数UploadPhotos(ByVal filename As String)As Boolean
尝试
Dim f As System.IO.File
Dim fs As System.IO。 FileStream
Dim Service As New host.Service
Dim credentials As System.Net.NetworkCredential = New
System.Net。 NetworkCredential(" username"," password")
Service.Credentials = credentials
Service.Url = ServiceUrl
Service.Timeout = 1800000
Dim TstUpload As String
fs = f.Open(UploadDirectory& filename,IO.FileMode.Open,
IO.FileAccess.Read)
Dim b(CInt(fs.Length) - 1)By Byte
fs.Read(b,0,CInt(fs.Length))
尝试
TstUpload = Service.UploadFile(b,filename).ToString
Catch ex As Exception
Msgbox(ex.StackTrace.ToString)
返回错误
结束尝试
f =没什么
fs.Close()
Service.Dispose()
返回True
Catch ex As Exception
Msgbox(ex.StackTrace.ToString)
返回错误
结束尝试
结束功能
后端Web服务代码:
< WebMethod()>公共函数UploadFile(ByVal fs()As Byte,ByVal FlName As
String)As Boolean
试试
Dim m As New System.IO.MemoryStream(fs)
Dim f As New System.IO.FileStream(" e:\ folder1 \ folder2 \"& ; FlName,
IO.FileMode.Create)
m.WriteTo(f)
m.Close ()
f.Close()
f =没什么
m =没什么
返回真实
Catch ex As Exception
返回错误
结束尝试
结束功能
有些错误:
无法上传文件:db9431.zip底层连接是已关闭:
接收时发生意外错误。跟踪:
System.Web.Services.Protocols.WebClientProtocol.Ge tWebResponse(WebRequest
请求)
at
System.Web.Services.Protocols.HttpWebClientProtoco l.GetWebResponse(WebReques
t request)
在System.Web.Services.Protocols .SoapHttpClientProtoc ol.Invoke(String
methodName,Object []参数)
在sync.localhost.Service.UploadFile(Byte [] fs,String FlName )
在sync.Form1.UploadPhotos(字符串文件名)
无法上传文件:db9231.zip请求失败,http状态为401 :
访问被拒绝。跟踪:
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClient
消息消息,WebResponse响应,流响应流,布尔值
asyncCall)
在System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName,Object []参数)
在sync.localhost.Service.UploadFile(Byte [] fs,String FlName)
在sync.Form1.UploadPhotos(String filename)
Hello,
We have some code (see below) that has been working intermittently
and I was wondering if someone had a better approach or an idea on why we
get these errors. This part of code basically gets a file and uploads it
from a cable or DSL connection to our t1 line to a server. The file size
ranges from 1.7 MB to 4MB and there can be between 1-40 files that need to
be uploaded to our server. We also could have multiple laptops running this
application at the same time from different locations. The folder the file
is trying to be stored to has everyone with full permissions. Any help would
be greatly appreciated.
Front end vb app code:
Private Function UploadPhotos(ByVal filename As String) As Boolean
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim Service As New host.Service
Dim credentials As System.Net.NetworkCredential = New
System.Net.NetworkCredential("username", "password")
Service.Credentials = credentials
Service.Url = ServiceUrl
Service.Timeout = 1800000
Dim TstUpload As String
fs = f.Open(UploadDirectory & filename, IO.FileMode.Open,
IO.FileAccess.Read)
Dim b(CInt(fs.Length) - 1) As Byte
fs.Read(b, 0, CInt(fs.Length))
Try
TstUpload = Service.UploadFile(b, filename).ToString
Catch ex As Exception
Msgbox(ex.StackTrace.ToString)
Return False
End Try
f = Nothing
fs.Close()
Service.Dispose()
Return True
Catch ex As Exception
Msgbox(ex.StackTrace.ToString)
Return False
End Try
End Function
Backend Webservice code:
<WebMethod()> Public Function UploadFile(ByVal fs() As Byte, ByVal FlName As
String) As Boolean
Try
Dim m As New System.IO.MemoryStream(fs)
Dim f As New System.IO.FileStream("e:\folder1\folder2\" & FlName,
IO.FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return True
Catch ex As Exception
Return False
End Try
End Function
Some errors:
failed to upload file:db9431.zip the underlying connection was closed: an
unexpected error occurred on a receive. Trace: at
System.Web.Services.Protocols.WebClientProtocol.Ge tWebResponse(WebRequest
request)
at
System.Web.Services.Protocols.HttpWebClientProtoco l.GetWebResponse(WebReques
t request)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)
at sync.localhost.Service.UploadFile(Byte[] fs, String FlName)
at sync.Form1.UploadPhotos(String filename)
failed to upload file:db9231.zip the request failed with http status 401:
access denied. Trace: at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)
at sync.localhost.Service.UploadFile(Byte[] fs, String FlName)
at sync.Form1.UploadPhotos(String filename)
推荐答案
你好杰克,
我改变了一个使用网络服务的样本,有一个看看它。
在这个测试中我使用了一个XML数据集
我希望这有帮助吗?
Cor
\\\\需要一个图片框和一个窗口上的4个按钮
Dim ds作为新数据集
Private abyt()As Byte
私人新的OpenFileDialog
私人sf作为新的SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理Button1.Click
''正在阅读来自磁盘的图片并将其放入bytearray中
如果fo.ShowDialog = DialogResult.OK然后
Dim fs As New IO.FileStream(fo.FileName,_
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br。关闭()
''只显示没有文件读取错误的样本
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
结束如果
结束子
Private Sub Button2_Click(ByVal sender As System.Object,ByVal _
$ b $ as As System.EventArgs)处理Button2.Click
''将字节数据写入磁盘
如果sf.ShowDialog = DialogResult.OK那么
Dim fs As New IO.FileStream(sf.FileName,_
IO.FileMode。 CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End如果
End Sub
Private Sub Button3_Click(ByVal sender As System.Object,ByVal _
$ b $ as As System.EventArgs)Handles Button3.Click
''将bytearray写入web服务数据集
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)< br $>
End Sub
Private Sub Button4_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理Button4 。点击
''从网络服务数据集中读取图片
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte >
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
结束班级
////
\\\\Webservice
< WebMethod()> _
公共函数GetByte()As Byte()
Dim ds作为新数据集
ds.ReadXml(" C:\wsblob .xml")
返回CType(ds.Tables(0).Rows(0)(0),Byte())
结束函数
< WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds作为新数据集
ds.Tables.Add(New DataTable( 照片))
ds.Tables(0).Columns.Add(New DataColumn(" Sample"))
ds.Tables(0).Columns (0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0)= abyte
ds.WriteXml(" C:\wsblob.xml",XmlWriteMode.WriteSchema)
结束子
////
Hi Jake,
I have changed a sample I had by using a webservice, have a look to it.
In this test I use a XML dataset
I hope this helps?
Cor
\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
''Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
''just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
''writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
''writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
''reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
你好杰克,
我换了一个样本我通过使用网络服务,看看它。
在这个测试中我使用XML数据集
我希望这有帮助吗?
Cor
\\\\需要一个图片框和一个窗口上的4个按钮
Dim ds作为新数据集
私人abyt()作为字节
私有作为新OpenFileDialog
私人sf作为新SaveFileDialog
>
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理Button1.Click
''从磁盘读取图片并把它放在一个bytearray
如果fo.ShowDialog = DialogResult.OK然后
Dim fs As New IO.FileStream(fo.FileName,_
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
''只是为了显示没有fileread错误的样本
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
结束如果
结束子
私人Sub Button2_Click(ByVal sender As System.Object,ByVal _
$ b $ as As System.EventArgs)处理Button2.Click
''将字节数据写入磁盘
如果sf.ShowDialog = DialogResult.OK那么
Dim fs As New IO.FileStream(sf.FileName,_
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
结束如果
End Sub
Private Sub Button3_Click(ByVal sender As System.Object,ByVal _
$ b $ as As System.EventArgs)处理Button3.Click
''将bytearray写入web服务数据集
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)Handles Button4.Click
''从网络服务数据集中读取图片
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End班级
////
\\\\Webservice
< WebMethod()> _
公共函数GetByte()As Byte()
Dim ds作为新数据集
ds.ReadXml(" C:\wsblob .xml")
返回CType(ds.Tables(0).Rows(0)(0),Byte())
结束函数
< WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds作为新数据集
ds.Tables.Add(New DataTable( 照片))
ds.Tables(0).Columns.Add(New DataColumn(" Sample"))
ds.Tables(0).Columns (0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0)= abyte
ds.WriteXml(" C:\wsblob.xml",XmlWriteMode.WriteSchema)
结束子
////
Hi Jake,
I have changed a sample I had by using a webservice, have a look to it.
In this test I use a XML dataset
I hope this helps?
Cor
\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
''Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
''just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
''writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
''writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
''reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
您好Cor,
感谢您的样品。然而,这会将文件粘贴到数据库中,而我们实际上是在转移物理文件。看看我的
代码你能看到我们为什么会收到这些错误的任何问题吗?任何帮助
将不胜感激。
杰克
" Cor" < no*@non.com>在消息中写道
新闻:Os ************** @ TK2MSFTNGP11.phx.gbl ...
Hi Cor,
Thanks for the sample. However this sticks the file in a database while
we are actually transferring the physical files themselves. Looking at my
code can you see any issues with why we are getting those errors? Any help
would be greatly appreciated.
Jake
"Cor" <no*@non.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
嗨杰克,
我已经使用webservice改变了一个样本,看看它。
在这个测试中我使用的是XML数据集
我希望这有帮助吗?
需要一个图片框和窗口上的4个按钮
Dim ds As New DataSet
Private abyt ()作为Byte
私有作为新的OpenFileDialog
私有sf作为新的SaveFileDialog
私有子Button1_Click(ByVal发送者作为System.Object,_
ByVal e As System .EventArgs)处理Button1.Click
''从磁盘读取图片并将其放入bytearray
如果fo.ShowDialog = DialogResult.OK然后
Dim fs As New IO.FileStream(fo .FileName,_
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br .Close()
''只显示没有fileread错误的示例
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If <结束Sub
Private Sub Button2_Click(ByVal sender As System.Object,ByVal _
e As System.EventArgs)处理Button2.Click
''写一张图片来自一个bytearray到磁盘
如果sf.ShowDialog = DialogResult.OK然后
Dim fs As New IO.FileStream(sf.FileName,_
IO.FileMode.CreateNew)
Dim bw如新IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
结束如果
结束子
私人子按钮3_Click (ByVal sender As System.Object,ByVal _
e As System.EventArgs)处理Button3.Click
''将bytearray写入web服务数据集
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
私有子Button4_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理Button4.Click
''从webservice数据集中读取图片
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
我。 PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
< WebMethod ()> _
公共函数GetByte()As Byte()
Dim ds As New DataSet
ds.ReadXml(" C:\wsblob.xml")
返回CType(ds .Tables(0).Rows(0)(0),Byte())
结束函数
< WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable(" Photo"))
ds。表(0).Columns.Add(New DataColumn(" Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds。表(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0)= abyte
ds.WriteXml(" C: \wsblob.xml",XmlWriteMode.WriteSchema)
End Sub
////
Hi Jake,
I have changed a sample I had by using a webservice, have a look to it.
In this test I use a XML dataset
I hope this helps?
Cor
\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
''Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
''just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
''writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
''writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
''reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
这篇关于需要专家帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!