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

Visual Basic 6.0 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

 

 

 

(Visual Basic 6.0) 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

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

' 

' ------------------------------------
' Step 1: Load the signing certificate
' ------------------------------------
Dim cert As New ChilkatCert
Dim success As Long
success = cert.LoadFromSmartcard("")
If (success = 0) Then
    Debug.Print cert.LastErrorText
    Exit Sub
End If

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

Dim xml As New ChilkatXml
xml.Tag = "SOAP-ENV:Envelope"
success = xml.AddAttribute("xmlns:SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/")
success = xml.AddAttribute("xmlns:web","http://www.example.com/webservice/")
success = xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#")
success = 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")
success = 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")
success = xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"xmlns:xenc","http://www.w3.org/2001/04/xmlenc#")
success = xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security",1,"SOAP-ENV:mustUnderstand","1")
success = xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"A1","")
success = 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")
success = 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")
success = xml.UpdateAttrAt("SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","x509cert00")
xml.UpdateChildContent "SOAP-ENV:Header|wsse:Security|wsse:BinarySecurityToken",cert.GetEncoded()
success = xml.UpdateAttrAt("SOAP-ENV:Body",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
success = xml.UpdateAttrAt("SOAP-ENV:Body",1,"wsu:Id","TheBody")
xml.UpdateChildContent "SOAP-ENV:Body|web:MyRequest|web:Parameter","MyValue"

' ---------------------------------------
' Step 3: Sign the XML
' ---------------------------------------

Dim gen As New ChilkatXmlDSigGen

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

' -------- Reference 1 --------
success = gen.AddSameDocRef("TheBody","sha1","EXCL_C14N","wsu SOAP-ENV","")

success = gen.SetX509Cert(cert,1)

gen.KeyInfoType = "Custom"

' Create the custom KeyInfo XML..
Dim xmlCustomKeyInfo As New ChilkatXml
xmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference"
xmlCustomKeyInfo.Content = "5"
success = xmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#x509cert00")
success = xmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509")

xmlCustomKeyInfo.EmitXmlDecl = 0
gen.CustomKeyInfoXml = xmlCustomKeyInfo.GetXml()

' Load XML to be signed...
Dim sbXml As New ChilkatStringBuilder
xml.EmitXmlDecl = 0
success = xml.GetXmlSb(sbXml)

gen.Behaviors = "IndentedSignature"

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    Debug.Print gen.LastErrorText
    Exit Sub
End If

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

Dim http As New ChilkatHttp

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

Dim resp As ChilkatHttpResponse
Set resp = http.PTextSb("POST","https://example.com/MyWebService",sbXml,"utf-8","text/xml; charset=utf-8",0,0)
If (http.LastMethodSuccess = 0) Then
    Debug.Print http.LastErrorText
    Exit Sub
End If

Debug.Print resp.StatusCode
Debug.Print resp.BodyStr

Debug.Print "Finished."

 

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