WCF服务无效的投射

时间:2017-04-10 20:55:46

标签: vb.net wcf

所以我正在开发一个用VB.NET编写的丑陋的遗留Windows窗体项目。我试图让它使用我之前写过的WCF Web服务。当我在本地测试它时,一切正常,但是,当我将服务部署到我的DEV环境(我有DEV,QA和生产环境),然后在我的win表单应用程序中更改配置文件指向DEV服务然后运行应用程序,它给我一个“无效的强制转换异常”。我完全糊涂了。

Windows窗体如下所示: enter image description here

基本上用户所做的就是更改复选框。复选框发生任何更改都会触发Windows窗体中的“Security_ColumnChanging()”函数:

 Private Sub Security_ColumnChanging(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs)
    Try
        Dim intPersonnel_Id As Integer = m_oDS.Tables("Security").Rows(DataGrid1.CurrentRowIndex)("ID")
        Dim groupId As Integer

        Select Case UCase(e.Column.ColumnName)
            Case "ADMINREPORTS"
                groupId = 1
            Case "BATCH"
                groupId = 2
            Case "SECURITY"
                groupId = 3
            Case "GLOBALRULE"
                groupId = 4
            Case "PROFILES"
                groupId = 5
        End Select

        If e.ProposedValue Then
            dataSource.AddGroupForUser(intPersonnel_Id, groupId)
        Else
            dataSource.DeleteGroupForUser(intPersonnel_Id, groupId)
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

您可以看到还有一个数据源类,它将处理所有数据库插入和删除。数据源类中的两个函数是:

Public Class SecurityFormDataSource
Public Sub AddGroupForUser(userID As Integer, groupID As Integer)
    Using proxy As Service.AuthenticationService.AuthenticationServiceClient = New Service.AuthenticationService.AuthenticationServiceClient()
        Dim success As Boolean = proxy.AddGroupForUser(userID, groupID, Guid.Empty)
        If success = False Then
            Throw New Exception("Error happened on the service side.")
        End If
    End Using
End Sub

Public Sub DeleteGroupForUser(userID As Integer, groupID As Integer)
    Using proxy As Service.AuthenticationService.AuthenticationServiceClient = New Service.AuthenticationService.AuthenticationServiceClient()
        Dim success As Boolean = proxy.DeleteGroupForUser(userID, groupID, Guid.Empty)
        If success = False Then
            Throw New Exception("Error happened on the service side.")
        End If
    End Using
End Sub
End Class

数据源类最终调用“身份验证服务”中的函数来实际插入或删除数据库记录。当我在本地计算机上运行服务时,一切都运行良好,但在我将服务部署到我的任何环境然后再次测试Windows窗体后,我有这样的错误: enter image description here

堆栈跟踪是:

   at System.Windows.Forms.DataGridBoolColumn.Paint(Graphics g, Rectangle   bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush foreBrush, Boolean alignToRight)
   at System.Windows.Forms.DataGridRelationshipRow.PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush foreBrush, Boolean alignToRight)
   at System.Windows.Forms.DataGridRow.PaintData(Graphics g, Rectangle bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)
   at System.Windows.Forms.DataGridRelationshipRow.Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32 numVisibleColumns, Boolean alignToRight)
   at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle& boundingRect)
   at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
   at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

0 个答案:

没有答案