SOAP WSDL Generate Code

TimbradoSoap12Binding / timbrar

ASP AutoIt C C (Unicode) C++ C++ (Unicode) C# DataFlex Delphi Foxpro Go Java Node.js Objective-C Perl PHP Extension PowerBuilder Powershell PureBasic Python CkPython Ruby SQL Server Swift TCL VB.NET VB6 VBScript Xojo
func chilkatTest() {
    let xml = CkoXml()!
    xml.tag = "soap:Envelope"
    xml.addAttribute("xmlns:soap", value: "http://www.w3.org/2003/05/soap-envelope")
    xml.addAttribute("xmlns:ns", value: "http://timbrado.ws.cfdi.solucionfactible.com")
    xml.updateChildContent("soap:Header", value: "")
    xml.updateChildContent("soap:Body|ns:timbrar|ns:usuario", value: "string")
    xml.updateChildContent("soap:Body|ns:timbrar|ns:password", value: "string")
    xml.updateChildContent("soap:Body|ns:timbrar|ns:cfdi", value: "BqozVXeZZg==")
    xml.updateChildContent("soap:Body|ns:timbrar|ns:zip", value: "true")

    // In a SOAP HTTP request, including the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) in the XML body is generally not required. 
    xml.emitXmlDecl = false
    var soapRequestBody: String? = xml.getXml()

    var endpoint: String? = ""
    var soapAction: String? = "urn:timbrar"
    //  For SOAP requests, the standard Content-Type is usually set to "text/xml" or "application/soap+xml"
    var contentType: String? = "text/xml"

    let http = CkoHttp()!

    http.clearHeaders()
    http.setRequestHeader("Content-Type", value: contentType)
    http.setRequestHeader("SOAPAction", value: soapAction)

    var resp: CkoHttpResponse? = http.postXml(endpoint, xmlDoc: soapRequestBody, charset: "utf-8")
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        print("Failed to send SOAP request.")
        return
    }

    // Get the XML response body.
    let responseXml = CkoXml()!
    resp!.getBody(responseXml)

    var statusCode: Int = resp!.statusCode.intValue
    print("response status code: \(statusCode)")

    resp = nil

    // If the status code does not indicate succcess, then show the response XML,
    // which probably contains error information.
    if statusCode != 200 {
        print("\(responseXml.getXml()!)")
        return
    }

    print("\(responseXml.getXml()!)")

    // Parse the successful SOAP response XML.

    // This is a sample of the response XML, but the namespace prefixes will be different.
    // We can parse the result using "*" for the namespace prefixes (see below).

    var mensaje: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:mensaje")
    var cadenaOriginal: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:cadenaOriginal")
    var certificadoSAT: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:certificadoSAT")
    var cfdiTimbrado: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:cfdiTimbrado")
    var fechaTimbrado: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:fechaTimbrado")
    mensaje = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:mensaje")
    var qrCode: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:qrCode")
    var selloSAT: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:selloSAT")
    var status: Int = responseXml.getChildIntValue("*:Body|*:timbrarResponse|*:return|*:resultados|*:status").intValue
    var uuid: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:uuid")
    var versionTFD: String? = responseXml.getChildContent("*:Body|*:timbrarResponse|*:return|*:resultados|*:versionTFD")
    status = responseXml.getChildIntValue("*:Body|*:timbrarResponse|*:return|*:status").intValue

}
Request XML
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://timbrado.ws.cfdi.solucionfactible.com">
    <soap:Header/>
    <soap:Body>
        <ns:timbrar>
            <ns:usuario>string</ns:usuario>
            <ns:password>string</ns:password>
            <ns:cfdi>BqozVXeZZg==</ns:cfdi>
            <ns:zip>true</ns:zip>
        </ns:timbrar>
    </soap:Body>
</soap:Envelope>
Response XML
<soap:Envelope xmlns:ns="http://timbrado.ws.cfdi.solucionfactible.com" xmlns:ax27="http://timbrado.ws.cfdi.solucionfactible.com/xsd" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header/>
    <soap:Body>
        <ns:timbrarResponse>
            <ns:return>
                <ax27:mensaje>string</ax27:mensaje>
                <ax27:resultados>
                    <ax27:cadenaOriginal>string</ax27:cadenaOriginal>
                    <ax27:certificadoSAT>string</ax27:certificadoSAT>
                    <ax27:cfdiTimbrado>BqozVXeZZg==</ax27:cfdiTimbrado>
                    <ax27:fechaTimbrado>dateTime</ax27:fechaTimbrado>
                    <ax27:mensaje>string</ax27:mensaje>
                    <ax27:qrCode>BqozVXeZZg==</ax27:qrCode>
                    <ax27:selloSAT>string</ax27:selloSAT>
                    <ax27:status>1042</ax27:status>
                    <ax27:uuid>string</ax27:uuid>
                    <ax27:versionTFD>string</ax27:versionTFD>
                </ax27:resultados>
                <ax27:status>1042</ax27:status>
            </ns:return>
        </ns:timbrarResponse>
    </soap:Body>
</soap:Envelope>