WS.JS
A WS-* client stack for node.js. Written in pure javascript!
Currently supports:
- MTOM
- WS-Security (username tokens, x.509 digital signature)
- WS-Addressing (all versions)
- HTTP(S)
For more information visit my blog or my twitter.
Install
Install with npm:
npm install ws.js
Usage
WS-Security (Username)
var ws = Http = wsHttp Security = wsSecurity UsernameToken = wsUsernameToken var request = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">' + '<Header />' + '<Body>' + '<EchoString xmlns="http://tempuri.org/">' + '<s>123</s>' + '</EchoString>' + '</Body>' + '</Envelope>' var ctx = request: request url: "http://service/security" action: "http://tempuri.org/EchoString" contentType: "text/xml" var handlers = {} username: "yaron" password: "1234" ws
==>
2012-02-26T11:03:40Z 2012-02-26T11:08:40Z yaron 1234 123
WS-Security (digital signature)
var ws = fs = sec = wsSecurity X509BinarySecurityToken = wsX509BinarySecurityToken FileKeyInfo = FileKeyInfo var x509 = "key": fsvar signature = x509signaturesignature var sec = {} x509 signature var handlers = "http://www.w3.org/2005/08/addressing" sec request = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" + "<Header />" + "<Body>" + "<GetData xmlns='http://tempuri.org/'>" + "<value>123</value>" + "</GetData>" + "</Body>" + "</Envelope>" var ctx = request: request url: "http://localhost:7171/Service/signature" action: "http://tempuri.org/IService/GetData" contentType: "text/xml" ws
==>
http://tempuri.org/IService/GetData http://localhost:8888/ ca62b7d7-4f74-75ed-9f5c-b09b173f6747 http://www.w3.org/2005/08/addressing/role/anonymous 2012-05-25T12:18:38Z 2012-05-25T12:23:38Z MIIBxDCCAW6gAwIBAgIQxUSXFzWJYYtOZnmmuOMKkjANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtSb290IEFnZW5jeTAeFw0wMzA3MDgxODQ3NTlaFw0zOTEyMzEyMzU5NTlaMB8xHTAbBgNVBAMTFFdTRTJRdWlja1N0YXJ0Q2xpZW50MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+L6aB9x928noY4+0QBsXnxkQE4quJl7c3PUPdVu7k9A02hRG481XIfWhrDY5i7OEB7KGW7qFJotLLeMec/UkKUwCgv3VvJrs2nE9xO3SSWIdNzADukYh+Cxt+FUU6tUkDeqg7dqwivOXhuOTRyOI3HqbWTbumaLdc8jufz2LhaQIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwDQYJKoZIhvcNAQEEBQADQQAfIbnMPVYkNNfX1tG1F+qfLhHwJdfDUZuPyRPucWF5qkh6sSdWVBY5sT/txBnVJGziyO8DPYdu2fPMER8ajJfl fxQc0PEh2GHA43IXltm6gjbccsA= L+vrfEszbn2ZtXiWfNyDG8nM1e8= AcOb1KJHpyQnnChEZFKaIjVag8iREL7g+LEXnvHQ/wH9ffIj0s1sdF2xO2AvQkqLUeefIEPgyiKUPR9sk8RMchJxv7UDx8wGuvD2WFPbd3yy50qcsu2UkiUm0lW/R3lpv88w83Z95LFZ1yq1MnOe2Sh0y5esoCbJo1fJETS8mQ0= 123
Notes:
By default incoming signatures are not validates. To validate these signatures when you create the security channel specify the validateResponseSignature parameter:
var sec = "validateResponseSignature": true ...
Next specify the server certificate (the public key corresponding to the server private sgining key):
secoptionsresponseKeyInfoProvider = "./examples/server_public.pem"
In the future the server certificate will be extracted from the BinarySecurityToken automatically (when available).
MTOM
var ws = Http = wsHttp Mtom = wsMtom var request = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' + '<s:Body>' + '<EchoFiles xmlns="http://tempuri.org/">' + '<File1 />' + '</EchoFiles>' + '</s:Body>' + '</s:Envelope>' var ctx = request: request contentType: "application/soap+xml" url: "http://localhost:7171/Service/mtom" action: "http://tempuri.org/IService/EchoFiles" //add attachment to the soap request ws var handlers = ; ws
==>
--my_unique_boundary Content-ID: Content-Transfer-Encoding: 8bit Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml" --my_unique_boundary Content-ID: Content-Transfer-Encoding: binary Content-Type: image/jpeg [binary here...]
WS-Addressing
var ws = Http = wsHttp Addr = wsAddr ctx = request: "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" + "<Header />" + "<Body>" + "<EchoString xmlns='http://tempuri.org/'>" + "<s>123</s>" + "</EchoString>" + "</Body>" + "</Envelope>" url: "http://localhost/service" action: "http://tempuri.org/EchoString" contentType: "text/xml" var handlers = "http://schemas.xmlsoap.org/ws/2004/08/addressing" ws
==>
http://tempuri.org/EchoString http://server/wsa/ 6c4189e5-60f5-195e-b7ce-4e236d63c379 http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous 123
SSL
Just specify an https address in any of the previous samples.
All together now
var ws = Http = wsHttp Addr = wsAddr Mtom = wsMtom Security = wsSecurity UsernameToken = wsUsernameToken ctx = request: "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" + "<Header />" + "<Body>" + "<EchoString xmlns='http://tempuri.org/'>" + "<File1 />" + "</EchoString>" + "</Body>" + "</Envelope>" url: "https://localhost/service" action: "http://tempuri.org/EchoString" contentType: "text/xml" ws var handlers = {} username: "yaron" password: "1234" "http://ws-addressing/v8" //Mtom must be after everything except http ws
License
This software is licensed udner the MIT license.
Copyright (C) 2012 Yaron Naveh (mail, blog)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
More details
- http://webservices20.blogspot.com/
- Or drop me an email