Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) HTTP request for a SOAP web service using WS-Security 1.0 with a digital certificate for authentication

See more HTTP Examples

Demonstrates how to build and send an HTTP request for a SOAP web service using WS-Security 1.0 with a digital certificate for authentication.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Cert
integer li_Success
oleobject loo_Xml
oleobject loo_Gen
oleobject loo_XmlCustomKeyInfo
oleobject loo_SbXml
oleobject loo_Http
oleobject loo_Resp

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

// 

// ------------------------------------
// Step 1: Load the signing certificate
// ------------------------------------
loo_Cert = create oleobject
// Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
if li_rc < 0 then
    destroy loo_Cert
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Cert.LoadFromSmartcard("")
if li_Success = 0 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Cert
    return
end if

// ---------------------------------------
// Step 2: Build the SOAP XML to be signed
// ---------------------------------------

loo_Xml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_Xml.Tag = "SOAP-ENV:Envelope"
loo_Xml.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/")
loo_Xml.AddAttribute("xmlns:web","http://www.example.com/webservice/")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:xenc","http://www.w3.org/2001/04/xmlenc#")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"SOAP-ENV:mustUnderstand","1")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"A1","")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509")
loo_Xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","x509cert00")
loo_Xml.UpdateChildContent("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",loo_Cert.GetEncoded())
loo_Xml.UpdateAttrAt("SOAP-ENV:Body",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
loo_Xml.UpdateAttrAt("SOAP-ENV:Body",1,"wsu:Id","TheBody")
loo_Xml.UpdateChildContent("SOAP-ENV:Body|web:MyRequest|web:Parameter","MyValue")

// ---------------------------------------
// Step 3: Sign the XML
// ---------------------------------------

loo_Gen = create oleobject
// Use "Chilkat_9_5_0.XmlDSigGen" for versions of Chilkat < 10.0.0
li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen")

loo_Gen.SigLocation = "SOAP-ENV:Envelope|SOAP-ENV:Header|wsse:Security"
loo_Gen.SigLocationMod = 0
loo_Gen.SigNamespacePrefix = "ds"
loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
loo_Gen.SignedInfoPrefixList = "ds wsu xenc SOAP-ENV "
loo_Gen.IncNamespacePrefix = "c14n"
loo_Gen.IncNamespaceUri = "http://www.w3.org/2001/10/xml-exc-c14n#"
loo_Gen.SignedInfoCanonAlg = "EXCL_C14N"
loo_Gen.SignedInfoDigestMethod = "sha1"

// -------- Reference 1 --------
loo_Gen.AddSameDocRef("TheBody","sha1","EXCL_C14N","wsu SOAP-ENV","")

loo_Gen.SetX509Cert(loo_Cert,1)

loo_Gen.KeyInfoType = "Custom"

// Create the custom KeyInfo XML..
loo_XmlCustomKeyInfo = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_XmlCustomKeyInfo.ConnectToNewObject("Chilkat.Xml")

loo_XmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference"
loo_XmlCustomKeyInfo.Content = "5"
loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#x509cert00")
loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509")

loo_XmlCustomKeyInfo.EmitXmlDecl = 0
loo_Gen.CustomKeyInfoXml = loo_XmlCustomKeyInfo.GetXml()

// Load XML to be signed...
loo_SbXml = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")

loo_Xml.EmitXmlDecl = 0
loo_Xml.GetXmlSb(loo_SbXml)

loo_Gen.Behaviors = "IndentedSignature"

// Sign the XML...
li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml)
if li_Success <> 1 then
    Write-Debug loo_Gen.LastErrorText
    destroy loo_Cert
    destroy loo_Xml
    destroy loo_Gen
    destroy loo_XmlCustomKeyInfo
    destroy loo_SbXml
    return
end if

// ---------------------------------------------------------
// Step 4: Send the HTTP POST containing the Signed SOAP XML
// ---------------------------------------------------------

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

loo_Http.SetRequestHeader("SOAPAction","~"http://www.example.com/MyWebService~"")
loo_Http.SetRequestHeader("Host","www.example.com")
loo_Http.SetRequestHeader("Content-Type","text/xml; charset=utf-8")

loo_Resp = loo_Http.PTextSb("POST","https://example.com/MyWebService",loo_SbXml,"utf-8","text/xml; charset=utf-8",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Cert
    destroy loo_Xml
    destroy loo_Gen
    destroy loo_XmlCustomKeyInfo
    destroy loo_SbXml
    destroy loo_Http
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp

Write-Debug "Finished."


destroy loo_Cert
destroy loo_Xml
destroy loo_Gen
destroy loo_XmlCustomKeyInfo
destroy loo_SbXml
destroy loo_Http

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.