Sample code for 30+ languages & platforms
PureBasic

SOAP Request to fseservicetest.sanita.finanze.it with Smart Card Authentication (TS-CNS Italian Card)

See more HTTP Misc Examples

Demonstrates sending a SOAP request to fseservicetest.sanita.finanze.it with Smart Card (TS-CNS Italian Card).

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCert.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkXml.pb"
IncludeFile "CkHttpRequest.pb"

Procedure ChilkatExample()

    success.i = 0

    ; This example requires the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = 0

    ; --------------------------------------------------------------------------------
    ; Also see Chilkat's Online WSDL Code Generator
    ; to generate code and SOAP Request and Response XML for each operation in a WSDL.
    ; --------------------------------------------------------------------------------

    ; Create the SOAP envelope...
    CkXml::setCkTag(xml, "soapenv:Envelope")
    CkXml::ckAddAttribute(xml,"xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
    CkXml::ckAddAttribute(xml,"xmlns:stat","http://statoconsensirichiesta.xsd.fse.ini.finanze.it")
    CkXml::ckAddAttribute(xml,"xmlns:tip","http://tipodatistatoconsensi.xsd.fse.ini.finanze.it")
    CkXml::ckUpdateChildContent(xml,"soapenv:Header","")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:IdentificativoUtente","XXXXXXAAABBBCCC")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:pinCode","...")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:IdentificativoOrganizzazione","999")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:StrutturaUtente","123456789")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:RuoloUtente","ZZZ")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:ContestoOperativo","")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:IdentificativoAssistitoGenitoreTutore","")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:PresaInCarico","true")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:TipoAttivita","READ")
    CkXml::ckUpdateChildContent(xml,"soapenv:Body|stat:StatoConsensiRichiesta|stat:IdentificativoAssistitoConsenso","ABCDEFGHIJKLM")
    soapEnvelope.s = CkXml::ckGetXml(xml)

    domain.s = "fseservicetest.sanita.finanze.it"
    path.s = "/FseInsServicesWeb/services/fseStatoConsensi"

    req.i = CkHttpRequest::ckCreate()
    If req.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpRequest::setCkHttpVerb(req, "POST")
    CkHttpRequest::setCkSendCharset(req, 0)
    CkHttpRequest::ckAddHeader(req,"Content-Type","application/soap+xml; charset=utf-8")
    CkHttpRequest::setCkPath(req, path)
    success = CkHttpRequest::ckLoadBodyFromString(req,soapEnvelope,"utf-8")

    ; Load the default certificate from the smartcard currently in the reader.
    ; (This assumes only one reader with one smartcard containing one certificate.
    ; If the situation is more complex, you can do it with Chilkat, but it requires
    ; using the Chilkat certificate store object to get the desired certificate
    ; from the desired smart card.)
    ; 
    ; Note: This is for Windows-only.
    cert.i = CkCert::ckCreate()
    If cert.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkCert::ckLoadFromSmartcard(cert,"")
    If success = 0
        Debug CkCert::ckLastErrorText(cert)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        CkHttpRequest::ckDispose(req)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    ; Tell the Chilkat HTTP object to use the certificate for client authentication.
    success = CkHttp::ckSetSslClientCert(http,cert)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        CkHttpRequest::ckDispose(req)
        CkCert::ckDispose(cert)
        ProcedureReturn
    EndIf

    CkHttp::setCkTlsVersion(http, "TLS 1.1")

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpSReq(http,domain,443,1,req,resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkXml::ckDispose(xml)
        CkHttpRequest::ckDispose(req)
        CkCert::ckDispose(cert)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    xmlResp.i = CkXml::ckCreate()
    If xmlResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkXml::ckLoadXml(xmlResp,CkHttpResponse::ckBodyStr(resp))
    Debug CkXml::ckGetXml(xmlResp)


    CkHttp::ckDispose(http)
    CkXml::ckDispose(xml)
    CkHttpRequest::ckDispose(req)
    CkCert::ckDispose(cert)
    CkHttpResponse::ckDispose(resp)
    CkXml::ckDispose(xmlResp)


    ProcedureReturn
EndProcedure