Ошибка запроса SOAP ... почему я получаю NRE? - PullRequest
0 голосов
/ 17 апреля 2011

Я в значительной степени копирую и вставляю код из API PDF, но получаю исключение пустой ссылки в строке:

AccountArray(0) = AccountToUpdate

Кто-нибудь знает, что я делаю неправильно?Спасибо!

Dim boolQueryFinished = False
Dim strCurrentID As String = "0"
Dim contractid As Integer
Dim strWebURI As String = "https://webservices.autotask.net/atservices/1.5/atws.asmx"
Dim myService As New ATWS
myService.Url = strWebURI
Dim cred As New System.Net.NetworkCredential("U", "P")
Dim credCache As New System.Net.CredentialCache
credCache.Add(New Uri(myService.Url), "Basic", cred)
myService.Credentials = credCache
Dim AccountID As New ArrayList
Dim i As Integer
While Not (boolQueryFinished)
Dim strQuery As String = "<queryxml><entity>Contract</entity>" & _
"<query><condition><field>id<expression op=""greaterthan"">" & strCurrentID &
"</expression></field></condition></query>" & _
"</queryxml>"
Dim r As ATWSResponse
r = myService.query(strQuery)
If r.EntityResults.Length > 0 Then
    For Each ent As Entity In r.EntityResults 
        strCurrentID = ent.id
        AccountID.Add(CType(ent, Contract).AccountID)

    Next
Else
    boolQueryFinished = True
    While i < ContractName.Count
        listOutput.Items.Add(ContractName(i))
        listOutput.Items.Add(id(i))
        If ContractName(i).Contains("Georges") Then
            listOutput.Items.Add("Found it")
            Dim sResponse As ATWSResponse
            Dim AccountToUpdate As New Contract
            Dim AccountArray(0) As Contract
            AccountToUpdate.AccountID = AccountID(i)


            AccountArray(0) = AccountToUpdate
            Dim entityArray() As Entity = CType(AccountArray, Entity())
            sResponse = myService.update(entityArray)

            If sResponse.ReturnCode = 1 Then
                listOutput.Items.Add("Updated")
            Else
                listOutput.Items.Add("Failed")

            End If
        End If

        i = i + 1
    End While
    listOutput.Items.Add(id.Count)
    listOutput.Items.Add(ContractName.Count)
End If
End While

1 Ответ

0 голосов
/ 17 апреля 2011

Похоже, что:

  • r.EntityResults.Length не больше нуля. Вы попали в предложение else.
  • Введен цикл While i < ContractName.Count (хотя не ясно, что это за ContractName.
  • i еще не инициализирован, поэтому его значение равно 0.
  • Из того, что мы видим в посте выше, мы должны были видеть ArgumentOutOfRange Exception, так как мы пытаемся добраться до индекса 0 пустого ArrayList.


AccountToUpdate.AccountID = AccountID (i)

Вы уверены, что хотите иметь цикл While в блоке Else? Мне любопытно, где выражение End If?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...