NetTalk Central

Author Topic: how to keep http session alive with multiple soap posts  (Read 3782 times)

joep

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
how to keep http session alive with multiple soap posts
« on: August 02, 2018, 06:48:44 AM »
Hi All,

I have to make 2 soap posts to a webservice.
- first request (in xml) provides the webservice with some parameters like (username, password, system etc..
   in return I receive "<connectResult>true</connectResult>" in xml, so I know the connection succeeded.
- In the above packetreceived I then know I can perform the second post.

This works, but the second time I get a "not connected" from the server.
What can I do to keep the session alive?

The first post:
          lCountRequest=0
          PostString = '<?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>'&|
                                 '<Connect xmlns="http://bct.nl">'&|
                                    '<ApplicationID>AAG</ApplicationID>'&|
                                    '<ConnectionID>'&Glo:DmsDbId&'</ConnectionID>'&|
                                    '<UserName>system</UserName>'&|
                                    '<Password>sys</Password>'&|
                                    '<EncodedPass>false</EncodedPass>'&|
                                 '</Connect>'&|
                              '</soap:Body>'&|
                     '</soap:Envelope>'

            cSoap.CanUseProxy = 1           ! Can use a proxy
        cSoap.HeaderOnly = 0            ! We want the whole page
        cSoap.AsyncOpenUse = 1          ! Use AsyncOpen 12 seconds (recommended)
        cSoap.AsyncOpenTimeOut = 1200   ! Up to 12 seconds to connect
        cSoap.InActiveTimeout = 9000    ! Set IdleTimeout 90 seconds
        cSoap.ConnectionKeepAlive = 0
        cSoap.ContentType = 'text/xml; charset=utf-8'
        cSoap.AcceptEncoding = ''
        cSoap.ContentLength = Len(Clip(PostString))

        ! Set the SOAPAction header to tell the web service which method to execute
        cSoap.customheader = 'SOAPAction: "http://bct.nl/Connect"'

        PacketSent = PostString
            clear(PacketReceived)
        cSoap.Post('http://localhost/wsCorsa7/Corsa72WS.asmx', Clip(PostString))
        If cSoap.Error
           Message ('Could not be post the SOAP request to this web service. Error ' & cSoap.Error |
                    & ': ' & cSoap.InterpretError())
           SetCursor()
        end
       
Second post:

          PostString = '<?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>'&|
                                 '<GetFileVersion xmlns="http://bct.nl">'&|
                                    '<ObjectType>S</ObjectType>'&|
                                    '<ObjectID>'&Clip(Glo:DmsLastDoc)&'</ObjectID>'&|
                                    '<FileType>ftArchive</FileType>'&|
                                    '<FileVersion>0</FileVersion>'&|
                                 '</GetFileVersion>'&|
                              '</soap:Body>'&|
                     '</soap:Envelope>'

        cSoap.customheader = 'SOAPAction: "http://bct.nl/GetFileVersion"'

        ! The packet is contstructed, so you can post it to the webservice
        PacketSent = PostString
            clear(PacketReceived)
            !PostUrl = 'http://localhost/wsCorsa7/Corsa72WS.asmx'
        cSoap.Post('http://localhost/wsCorsa7/Corsa72WS.asmx', Clip(PostString))
        If cSoap.Error
           Message ('Could not be post the SOAP request to this web service. Error ' & cSoap.Error |
                    & ': ' & cSoap.InterpretError())
           SetCursor()
        end


Regards Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11176
    • View Profile
Re: how to keep http session alive with multiple soap posts
« Reply #1 on: August 02, 2018, 09:54:19 PM »
Hi Joep,

Calls to POST are Asynchronous - meaning that they take time to complete. so checking for an Errorcode on the next line is not useful.

>> If cSoap.Error

This is not refering to the post - it's refering to whatever happens to be in this property.


To make matters worse, calling MESSAGE will result in you breaking any actual comms which is happening in the background.

>>            Message ('Could not be post the SOAP request to this web service. Error ' & cSoap.Error |
                    & ': ' & cSoap.InterpretError())
           SetCursor()
>>         end

so, basically just remove all this code.
Put your error detection in the ErrorTrap method.

cheers
Bruce


joep

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
Re: how to keep http session alive with multiple soap posts
« Reply #2 on: August 02, 2018, 11:42:57 PM »
Hi Bruce,

I removed all the messages and error handlings.
So I don't get any error. the posts get a nice message back
But I still got a not connected message back.
This is my packetrecieved embed:

If Self.ThisPage.Length() > 0
   PacketReceived = Self.ThisPage.GetValue()
   str.SetValue(PacketReceived)
End
If lCountRequest = 0
   lResult = str.Between('<ConnectResult>','</ConnectResult>')
   If lResult = 'true'
      Do PostCorsaVersie !Is the second post
      lCountRequest=1
   Else
      !Message('Connectie met Corsa niet gelukt!')
      Post(EVENT:CloseWindow)
   End
Else
   lExtensie=str.Between('<FileExtension>','</FileExtension>')
   lFile=str.Between('<FileBytes>','</FileBytes>')   
   str.SetValue(lFile)
   str.Base64Decode()
   lFileName='e:\temp\' & Clip(Glo:DmsLastDoc) & Clip(lExtensie)
   str.SaveFile(lFileName)
   If Exists(lFileName) Then ShowFoto(lFileName).
End

And this is what I'm getting back from the second post:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/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">
   <soap:Header>
      <wsa:Action>http://bct.nl/GetFileVersionResponse</wsa:Action>
      <wsa:MessageID>urn:uuid:490fae00-8b6f-4766-9622-311c63432284</wsa:MessageID>
      <wsa:RelatesTo>urn:uuid:a5fc6d82-59ab-44a2-b25e-57c9a73b3966</wsa:RelatesTo>
      <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
      <wsse:Security>
         <wsu:Timestamp wsu:Id="Timestamp-356a5795-e554-4925-9ad7-9d1da6b1731f">
            <wsu:Created>2018-08-03T07:00:29Z</wsu:Created>
            <wsu:Expires>2018-08-03T07:05:29Z</wsu:Expires>
         </wsu:Timestamp>
      </wsse:Security>
   </soap:Header>
   <soap:Body>
      <GetFileVersionResponse xmlns="http://bct.nl">
         <GetFileVersionResult>false</GetFileVersionResult>
         <LastError>Unable to execute function, not connected or session was abandoned</LastError>
      </GetFileVersionResponse>
   </soap:Body>
</soap:Envelope>


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11176
    • View Profile
Re: how to keep http session alive with multiple soap posts
« Reply #3 on: August 03, 2018, 12:01:15 AM »
Hi Joep,

note that you are getting a response back from the remote server.
So it's not like your connection to them is broken or anything like that, it's specifically that they had a problem on their end, and they are reporting that problem to you.

So typically you would refer to their docs, or support, to better understand what the error means. It is, after all, _their_ error.

One thing I might suggest for you though, before the _first_ post is to set

  cSoap.OptionAutoCookie = true.

Then if they are returning a cookie with the first request, you are at least submitting that with the second request.

cheers
Bruce


joep

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
Re: how to keep http session alive with multiple soap posts
« Reply #4 on: August 03, 2018, 12:55:30 AM »
Hi Bruce,

Your last remark did the trick.
after setting   cSoap.OptionAutoCookie = true   I get the right response.

Thanks again,
Joep