Hi Suwing,
IMO, VBScript is the worst choice for WebServices testing in TestComplete because it does not support (in elegant way) exceptions handling.
I tested WebServices using DelphiScript (and I think that JScript should be equally good) and the general skeleton for the test looked like this:
try
try
WebServices.WebService.Method(<parm1>, <parm2>);
except
if ([the thrown exception was expected one])
Log.Message([post evidence that expected exception was thrown]);
else
Log.Error(ExceptionMessage);
finally
[cleanup code]
Unfortunately, as it was said, the above is not possible with VBScript.
The only thing that I can suggest for VBScript is to block error handling (which is a bad but the only possible practice in this case), call WebService method, check result, turn on error handling and further process result if necessary. I.e. something like this:
On Error Resume Next
Call WebServices.WebService.Method(<parm1>, <parm2>)
iErr = Err.Number
If (0 <> iErr) Then
strErrDescr = Err.Description
On Error GoTo 0
Call Log.Message("Request result", WebServices.WebService.LastRequest.xml)
Call Log.Message("Error code: " & iErr, strErrDescr)
[Further process error here]
End If
On Error GoTo 0
[Proceed with the test flow]
Note, that (IMO) you must disable error handling only for the method call and restore it immediately after you checked the call result. I would not recommend to disable error handling in the beginning of the test because in this case you are in risk to miss some unexpected test error and might spend a lot of time trying to figure out why the test does not behave as expected.
Also, it is not possible to move the error verification code to the separate function, because the Err object will be reset when this function is called and you will lost the information that the WebService method failed. Thus, the error verification code block must be repeated after every line that calls WebService method and this obviously is not handy and makes code less clear and supportable.
Also note, that since IIS7, the server by default do not return exception from WebService to the client, but replaces it with the html error page for code 500. This may require additional web server setup to make it return exception but not the error page.
Hope the above appear to be useful...