B4J Question Help with SOAP error

ToolboxZX

Member
Licensed User
Longtime User
I have looked at a number of examples on the forum and thought I had a handle on how to post a SOAP request and process a response. So I decided to try and create a new simple SOAP request myself.

After I found a valid WSDL, ( https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl ) I used the tool SOAPUI as a helper to form the XML request needed to request the LatLonListZipCode.

But no matter what I attempt, I get an internal server error response. So I feel that I must be just missing something basic here.

I am using the library jOKHttpUtils2(Version 2.40)

Code follows:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show

    
    Dim j As HttpJob
    j.Initialize("j", Me)
    Dim msg As String = $"<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ndf="https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl">
   <soapenv:Header/>
   <soapenv:Body>
      <ndf:LatLonListZipCode soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <zipCodeList xsi:type="xsd:string">44145</zipCodeList>
      </ndf:LatLonListZipCode>
   </soapenv:Body>
</soapenv:Envelope>
    "$
    
    j.PostString("https://graphical.weather.gov:443/xml/SOAP_server/ndfdXMLserver.php", msg)


    


End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub




Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "j"
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
    End If
    Job.Release
    
End Sub

The log window displays:
Waiting for debugger to connect...
Program started.
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Operation &apos;&apos; is not defined in the WSDL for this service</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
JobName = j, Success = false
Error: Internal Server Error
 

ToolboxZX

Member
Licensed User
Longtime User
Sorry to bother everyone, I figured it out. :)
Solution:
1) When all else fails, read Erel's notes! Upgrade the jOkHttpUtils2 internal library to version 2.70
2) To be able to utilize the parameter "SetContentType" for the SOAP request type with: j.GetRequest.SetContentType, one must also have the library OkHttp selected as well and place this line after the post command. This command is missing in my above posted code. So once I updated jOkHttpUtils2 I started to get an "unsupported" response from the service.

I hope this helps someone else out.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
(Aaaargh! One minute late!!!!!!! :eek::mad: )

Your SOAP message is well-formed. I was testing it with PostMan (saves a lot of time) and had the same error. Modifying the Content-Type from application/x-www-form-urlencoded (was there by default) to text/xml; charset=ISO-8859-1 did the trick.

;)


 
Upvote 0
Top