SOAP Request error... why am I getting a NRE?
I pretty much copy and pasted the code from the API PDF, but am getting a Null reference Exception on line:
AccountArray(0) = AccountToUpdate
Anyone know what I am doing wrong? Thanks!
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
It appears that:
- The
r.EntityResults.Length
is not greater than zero. You've fallen into theelse
clause. - The
While i < ContractName.Count
loop was entered (it's not clear what thisContractName
is, though. i
isn't initialized yet, so it's value is0
.- From what we can see posted above, we should have seen an
ArgumentOutOfRange Exception
, as we're trying to get to index 0 of an empty ArrayList.
AccountToUpdate.AccountID = AccountID(i)
Are you sure you meant to have the While
loop within the Else
block? I'm curious where the End If
statement is?
精彩评论