B4J Question Internal Server Error

aaronk

Well-Known Member
Licensed User
Hi,

I originally had a issue trying to send a SOAP message/request but have now solved that issue. (http://www.b4x.com/android/forum/threads/help-with-soap-in-b4j.55088/)

Now when I send the request I am getting a error and the reply I am getting is as below:

B4X:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to process request. ---&gt; Data at the root level is invalid. Line 1, position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:...
Internal Server Error

Can't seem to work out where Line 1, Position 1 is?

The code I am using to send the request is as follows:

B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
 
End Sub

Sub AppStart (Args() As String)

    Dim job1 As HttpJob
       Dim requestSoapXML As String

       requestSoapXML = "<?xml version='1.0' encoding='utf-8'?>" & _
                    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" & _
                    "  <soap:Header>" & _
                    "    <CredentialsHeader xmlns='https://xxx.xxx.xxx.xxx/test/API'>" & _
                    "      <OrganizationID>1234</OrganizationID>" & _
                    "      <Username>Admin</Username>" & _
                    "      <Password>1234</Password>" & _
                    "    </CredentialsHeader>" & _
                    "  </soap:Header>" & _
                    "  <soap:Body>" & _
                    "    <ListAccounts xmlns='https://xxx.xxx.xxx.xxx/test/API' />" & _
                    "  </soap:Body>" & _
                    "</soap:Envelope>"
 

      job1.Initialize("JOB1", Me)
       job1.PostString("https://xxx.xxx.xxx.xxx/Accounts.asmx", requestSoapXML)

    StartMessageLoop
 
End Sub

Public Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Log(Job.GetString)
    End If
   Job.Release
End Sub
I do have the code working in VB.net but want to port it over to B4J since I have most of my other code working already in B4J, but if I can't solve the issue then I am going to have to port my B4J code to VB.net and give up with B4J and continue with VB.net.

I can't post my VB.net code in the forum but willing to send a PM to anyone that wants to help (serious people only please)

Anyone know where the error is happening ?
 

Erel

Administrator
Staff member
Licensed User
Why don't you use the new smart strings literal?
B4X:
requestSoapXML = $"
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
   <soap:Header>
     <CredentialsHeader xmlns='https://xxx.xxx.xxx.xxx/test/API'>
       <OrganizationID>1234</OrganizationID>
       <Username>Admin</Username>
       <Password>1234</Password>
     </CredentialsHeader>
   </soap:Header>
   <soap:Body>
     <ListAccounts xmlns='https://xxx.xxx.xxx.xxx/test/API' />
   </soap:Body>
</soap:Envelope>"$
Maybe you need to set the content type as done here: http://www.b4x.com/android/forum/threads/soap-textbox-info.19961/#post-155159 ?
The SOAPAction header is also sometimes required.
 

aaronk

Well-Known Member
Licensed User
Why don't you use the new smart strings literal?
I guess I could do that.

Yeah I have tied adding that but made no difference.

The SOAPAction header is also sometimes required
I tried that as well and still get the same error.

Are you interested in helping me converting the VB.net project (that works) to B4J if I PM you the VB.net project?
 

aaronk

Well-Known Member
Licensed User
Yeah I tired using WireShark but couldn't read what was being sent since it's a https request and the data was encrypted. (unless I was capturing the WireShark data wrong)
 

aaronk

Well-Known Member
Licensed User
Can't you temporary switch to http?
I did try http rather than https but the request didn't work so I am guessing it needs to be https.

I will have a play and see if I can get it to work with http so I can see what gets sent.
 
Top