B4J Question B4J Soap error

claudiob4

Member
Licensed User
Longtime User
Hi all,

I need to access a Soap server.

This is the example provided by the documentation (located at https://testfe.solutiondocondemand.com/solutiondoc_hub.asmx):


POST /solutiondoc_hub.asmx HTTP/1.1
Host: testfe.solutiondocondemand.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetFileElectronicInvoiceOutcome xmlns="http://tempuri.org/">
<paramAuth>
<CustomerCode>string</CustomerCode>
<Password>base64Binary</Password>
</paramAuth>
<paramFileOutcome>
<IdOutcome>string</IdOutcome>
</paramFileOutcome>
</GetFileElectronicInvoiceOutcome>
</soap12:Body>
</soap12:Envelope>


This is the subroutine that attempts to access:

B4X:
Private Sub GetResponsoFA As ResumableSub
  
    Dim jGF As HttpJob
    Dim Richiesta As String
    Dim ResJ As String

    DateTime.DateFormat="yyyy-MM-dd HH:mm:ss"
  
    Dim S As String = "D9E7F08E4A07E3D86CDCA0EB0452A45E"
    Dim Bytes() As Byte = s.GetBytes("UTF8")
    Dim I As Int
    S=""
    For I = 0 To Bytes.Length-1
        S=S & NumberFormat(Bytes(I),2,0)
    Next

    Richiesta="" & _
    "<?xml version='1.0' encoding='utf-8'?>" & _
    "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" & _
    "<soap12:Body>" & _
    "<GetFileElectronicInvoiceOutcome xmlns='http://tempuri.org/GetFileElectronicInvoiceOutcome'>" & _
    "<paramAuth>" & _
    "<CustomerCode>'0000001Test0001978'</CustomerCode>" & _
    "<Password>cid:" & S & "</Password>" & _
    "</paramAuth>" & _
    "<paramFileOutcome>" & _
    "<IdOutcome>'5680101'</IdOutcome>" & _
    "</paramFileOutcome>" & _
    "</GetFileElectronicInvoiceOutcome>" & _
    "</soap12:Body>" & _
    "</soap12:Envelope>"
  
    Richiesta=Richiesta.Replace("'","""")

    jGF.Initialize("GetWS", Me)
    jGF.PostString(UrlTest,Richiesta)
    jGF.GetRequest.SetContentType("application/soap+xml; charset=utf-8")

    Wait For (jGF) JobDone(j As HttpJob)
    If j.Success Then
        ResJ = j.GetString
'            Log(j.GetString)
        TxtRes.Text=ResJ
    Else
        Log(j.ErrorMessage)
        j.Release
        Log("Error Trades " & j.ErrorMessage)
        TxtRes.Text=j.ErrorMessage
        Return False
    End If
    j.Release
  
    Return True

End Sub

But I get this error:

<?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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"><wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action><wsa:MessageID>urn:uuid:4ce183a1-5eb5-4c3a-bd06-5cef5cd466bf</wsa:MessageID><wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-f5f20aa7-4351-40b1-ab2c-daaf63cc1e82"><wsu:Created>2018-12-12T18:10:02Z</wsu:Created><wsu:Expires>2018-12-12T19:10:02Z</wsu:Expires></wsu:Timestamp></wsse:Security></env:Header><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapHeaderException: WSE012: The input was not a valid SOAP message because the following information is missing: action.
at Microsoft.Web.Services3.Utilities.AspNetHelper.SetDefaultAddressingProperties(SoapContext context, HttpContext httpContext)
at Microsoft.Web.Services3.WseProtocol.CreateRequestSoapContext(SoapEnvelope requestEnvelope)
at Microsoft.Web.Services3.WseProtocol.FilterRequest(SoapEnvelope requestEnvelope)
at Microsoft.Web.Services3.WseProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>


Does anyone have any suggestions to give me?
Thank you


I attach the simple project.
 

Attachments

  • CONNETTORE_TEST.zip
    35.3 KB · Views: 254
Last edited:

claudiob4

Member
Licensed User
Longtime User
Ok I'll use the tags code ...
Tested but the error remains the same.
Thanks for the help in the meantime.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Which one of the methods on that page are you trying to call? Where is the updated code with smart string literal?

This code looks wrong:
B4X:
Dim S As String = "D9E7F08E4A07E3D86CDCA0EB0452A45E"
    Dim Bytes() As Byte = s.GetBytes("UTF8")
    Dim I As Int
    S=""
    For I = 0 To Bytes.Length-1
        S=S & NumberFormat(Bytes(I),2,0)
    Next
 
Upvote 0

claudiob4

Member
Licensed User
Longtime User
The string "D9E7F08E4A07E3D86CDCA0EB0452A45E" is provided by the company that manages the server. This value must be entered in the command as base64Binary. I do not know how else to convert it. In any case I would have the error: wrong password. The problem is even earlier.
The command I try to perform is GetFileElectronicInvoiceOutcome :

Example:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetFileElectronicInvoiceOutcome xmlns="http://tempuri.org/">
<paramAuth>
<CustomerCode>string</CustomerCode>
<Password>base64Binary</Password>
</paramAuth>
<paramFileOutcome>
<IdOutcome>string</IdOutcome>
</paramFileOutcome>
</GetFileElectronicInvoiceOutcome>
</soap12:Body>
</soap12:Envelope>


The complete code:



B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
   
    Private UrlTest As String = "https://testfe.solutiondocondemand.com/solutiondoc_hub.asmx"

    Private BtnInvia As Button
    Private TxtRes As TextArea
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("F1") 'Load the layout file.
    MainForm.Show
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

Private Sub GetResponsoFA As ResumableSub
   
    Dim jGF As HttpJob
    Dim Richiesta As String
    Dim ResJ As String

    DateTime.DateFormat="yyyy-MM-dd HH:mm:ss"
   
    Dim S As String = "D9E7F08E4A07E3D86CDCA0EB0452A45E"
    Dim Bytes() As Byte = s.GetBytes("UTF8")
    Dim I As Int
    S=""
    For I = 0 To Bytes.Length-1
        S=S & NumberFormat(Bytes(I),2,0)
    Next

    Richiesta="" & _
    "<?xml version='1.0' encoding='utf-8'?>" & _
    "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" & _
    "<soap12:Body>" & _
    "<GetFileElectronicInvoiceOutcome xmlns='http://tempuri.org/GetFileElectronicInvoiceOutcome'>" & _
    "<paramAuth>" & _
    "<CustomerCode>'0000001Test0001978'</CustomerCode>" & _
    "<Password>cid:" & S & "</Password>" & _
    "</paramAuth>" & _
    "<paramFileOutcome>" & _
    "<IdOutcome>'5680101'</IdOutcome>" & _
    "</paramFileOutcome>" & _
    "</GetFileElectronicInvoiceOutcome>" & _
    "</soap12:Body>" & _
    "</soap12:Envelope>"
   
    Richiesta=Richiesta.Replace("'","""")

    jGF.Initialize("GetWS", Me)
    jGF.PostString(UrlTest,Richiesta)
    jGF.GetRequest.SetContentType("application/soap+xml; charset=utf-8")
    jGF.GetRequest.SetHeader ("SOAPAction", $""http://tempuri.org/GetFileElectronicInvoiceOutcome""$)

    Wait For (jGF) JobDone(j As HttpJob)
    If j.Success Then
        ResJ = j.GetString
'            Log(j.GetString)
        TxtRes.Text=ResJ
    Else
        Log(j.ErrorMessage)
        j.Release
        Log("Error Trades " & j.ErrorMessage)
        TxtRes.Text=j.ErrorMessage
        Return False
    End If
    j.Release
   
    Return True

End Sub


Sub BtnInvia_Click
   
    Wait For (GetResponsoFA) complete(Result As Boolean)
   
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'll help you although you ignore my requests.

Make it is easier to help you and post the correct link: https://testfe.solutiondocondemand.com/solutiondoc_hub.asmx?op=GetFileElectronicInvoiceOutcome

This code seems to work properly:
B4X:
Dim s As String = $"<?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:Body>
<GetFileElectronicInvoiceOutcome xmlns="http://tempuri.org/">
  <paramAuth>
    <CustomerCode>string</CustomerCode>
    <Password>base64Binary</Password>
  </paramAuth>
  <paramFileOutcome>
    <IdOutcome>string</IdOutcome>
  </paramFileOutcome>
</GetFileElectronicInvoiceOutcome>
</soap:Body>
</soap:Envelope>"$
Dim j As HttpJob
j.Initialize("", Me)
j.PostString("https://testfe.solutiondocondemand.com/solutiondoc_hub.asmx", s)
j.GetRequest.SetContentType("text/xml")
j.GetRequest.SetHeader ("SOAPAction", $""http://tempuri.org/GetFileElectronicInvoiceOutcome""$)
Wait For JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
 
Upvote 0

claudiob4

Member
Licensed User
Longtime User
Excuse me but I did not understand how I had to write it.
For the rest really really exceptional. Everything works now. I figured out how to get a base64Binary value and the password also works.
Thank you so much for your help.

Here is the code with the data entered for access to the soap server:

B4X:
private Sub GetRes1
   
    Dim P As String = "D9E7F08E4A07E3D86CDCA0EB0452A45E"
    Dim Bytes() As Byte = P.GetBytes("UTF8")
    Dim su As StringUtils
    P=su.EncodeBase64(Bytes)
   
    Dim s As String = $"<?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:Body>
<GetFileElectronicInvoiceOutcome xmlns="http://tempuri.org/">
  <paramAuth>
    <CustomerCode>0000001Test0001978</CustomerCode>
    <Password>base64Binary</Password>
  </paramAuth>
  <paramFileOutcome>
    <IdOutcome>5680101</IdOutcome>
  </paramFileOutcome>
</GetFileElectronicInvoiceOutcome>
</soap:Body>
</soap:Envelope>"$

    s=s.Replace("base64Binary",P)
   
    Dim j As HttpJob
    j.Initialize("", Me)
    j.PostString("https://testfe.solutiondocondemand.com/solutiondoc_hub.asmx", s)
    j.GetRequest.SetContentType("text/xml")
    j.GetRequest.SetHeader ("SOAPAction", $""http://tempuri.org/GetFileElectronicInvoiceOutcome""$)
    Wait For JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        TxtRes.Text=j.GetString
    End If

End Sub
 
Upvote 0
Top