B4J Question SOAP Error when Passing Authorization Header


New Member
Licensed User
Longtime User
I am trying to make some SOAP API calls and am running into issues with authorization. The API requires you pass a basic authentication header. If I use the following:
Dim job1 As HttpJob

Dim SoapXML  As String= $"<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
job1.Initialize("SOAP_API", Me)
job1.poststring ("http://soap_endpoint_address", SoapXML)

job1.Username = usernamestring
job1.Password = passwordstring

wait for (job1) jobdone(job1 As HttpJob)   
If job1.Success Then
    Log(job1.ErrorMessage )
End If

If I comment out the .username and .password properties the webservice returns a properly formatted XML response indicating the request must include authentication in the message header as expected.

However, when I include the two lines to set the .username and .password properties then I get the following error message:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<ns0:Fault xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.w3.org/2003/05/soap-envelope">
Couldn't create SOAP message due to exception: XML reader error: 
com.ctc.wstx.exc.WstxParsingException: Unexpected '&lt;' character 
in element (missing closing '>'?) at [row,col {unknown-source}]: [3,2]

I am actually trying to port a small VB.net application to B4J. In VB I used the following code to successfully pass the authorization headers to the same SOAP API:

Dim mySOAPService As New WS_SOAP()

Dim myCredentials As New System.Net.CredentialCache()
Dim netCred As New NetworkCredential(username, password)
myCredentials.Add(New Uri(mySOAPService.Url), "Basic", netCred)
mySOAPService.Credentials = myCredentials

Any idea what i'm doing wrong here???


Licensed User
Longtime User
Upvote 0


New Member
Licensed User
Longtime User
Thanks for the find! It didn't solve the issue entirely but it did make me take another good look at the SOAPXML string. After fixing the ">" you noted as missing, I also noticed a stray:


Once I removed that I was good to go! Thanks for taking the time to put an extra set of eyes on a stupid little mistake...
Upvote 0