我想将 csv 文件中的记录从 Silverlight 前端导入数据库。我正在使用 WCF 服务来执行数据库操作。当我传递整个文件路径(硬编码)时,我可以将记录添加到数据库中,但是由于 Silverlight 中的 OpenFileDialog 不允许获取文件路径(出于安全原因),我尝试使用 WCF 服务并通过FileInfo 属性或 StreamReader,然后执行操作。但它给了我一个例外。我有以下代码 -
1) 传递 StreamReader Page.xaml.vb 文件
Dim service As New ServiceReference1.Service1Client
dlg.ShowDialog()
Dim Reader As System.IO.StreamReader
If dlg.File IsNot Nothing Then
Reader = dlg.File.OpenText
End If
service.ImportPersonInfoAsync(Reader)
'Service1.svc.vb 文件
<OperationContract()> _
Public Sub ImportPersonInfo(ByVal Reader As System.IO.StreamReader)
'Code to add records to DB table
End Sub
我遇到异常 - 远程服务器返回错误:NotFound(在 EndInvoke 方法中)
Public Sub EndImportPersonInfo(ByVal result As System.IAsyncResult) Implements ServiceReference1.Service1.EndImportPersonInfo
Dim _args((0) - 1) As Object
MyBase.EndInvoke("ImportPersonInfo", _args, result)
End Sub
2)传递文件信息
Page.xaml.vb 文件
If dlg.File IsNot Nothing Then
ImportFile = dlg.File
End If
service.ImportPersonInfoAsync(ImportFile)
Service1.svc.vb 文件
Public Sub ImportPersonInfo(ByVal ImportFile As System.IO.FileInfo)
Dim Reader As System.IO.StreamReader = ImportFile.OpenText
'Do operation
End Sub
我在 BeginInvoke 方法中遇到异常 - 尝试访问该方法失败:System.IO.FileSystemInfo.get_Attributes()
任何人都可以帮助我/建议解决方案或更好的方法来使用 Silverlight 将记录从 csv 导入数据库编程。
谢谢!