【问题标题】:ASP.NET System.FormatExceptionASP.NET System.FormatException
【发布时间】:2011-07-17 13:50:17
【问题描述】:

我有以下错误:

   Stack Trace:   
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)     
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)     
at DocumentManager.Web.MidasInterface.MIDASCustomerInfo.GetBaseRate(String ccy, String brcod) in D:\2010\RETAIL\DocumentManager.Web\Web References\MidasInterface\Reference.vb:line 696   
...

内心的讯息:

System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.    
at iMIDAS.MIDASCustomerInfo.GetBaseRate(String ccy, String brcod)    

db中的web方法查询

<WebMethod()> Public Function GetBaseRate(ByVal ccy As String, ByVal brcod As String) As ResponseObject
        Dim connAS400 As New Data.OleDb.OleDbConnection
        Dim dsAS400 As Data.DataSet
        Dim cmdAS400 As Data.OleDb.OleDbCommand
        Dim retVal As Object
        Try
            connAS400.ConnectionString = CreateConnectionStringMidas(DataSource, DataCatalog, DataUser, DataPassword)
            cmdAS400 = New Data.OleDb.OleDbCommand(CreateSQLBaseRate(ccy, brcod), connAS400)
            connAS400.Open()
            retVal = cmdAS400.ExecuteScalar()
            If IsNothing(retVal) Or IsDBNull(retVal) Then
                oResponse.ResponseState = False
                oResponse.ResponseMessage = String.Format("No Records Found for base rate code [{1}]!", brcod)
            Else
                oResponse.ResponseState = True
                oResponse.ResponseData = CType(retVal, String).ToString().ToUpper()
            End If
            Return oResponse
        Catch ex As Exception
            Throw ex
        Finally
            connAS400.Close()
        End Try
    End Function

有什么想法吗?

【问题讨论】:

  • 您应该提供有用的整个堆栈跟踪转储
  • 我在上面的代码中看到了各种潜在的异常。例如,你怎么知道 brcode 不为空?
  • 我不明白当 brcode 为空时应该发生什么??

标签: asp.net web-services exception


【解决方案1】:

我很确定是这一行:

oResponse.ResponseMessage = String.Format("No Records Found for base rate code [{1}]!", brcod)

应该是零索引,而不是一索引,所以:

oResponse.ResponseMessage = String.Format("No Records Found for base rate code [{0}]!", brcod)

【讨论】:

    猜你喜欢
    • 2015-02-21
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多