Enterprise Integration Zone is brought to you in partnership with:

Yaron is a Microsoft MVP in the Connected System Developer realm. Yaron authors the successful Web Services 2.0 blog, in which he helps the community with some of his favorite topics: Web services, security and interoperability. Yaron is also an architect in HP. Yaron is a DZone MVB and is not an employee of DZone and has posted 23 posts at DZone. You can read more from them at their website. View Full User Profile

WCF and CoffeeScript, Who Says That Opposites Don't Attract?

06.23.2012
| 2775 views |
  • submit to reddit
At first look Wcf and CoffeeScript are very different: Wcf is chatty on the config side and bloated on the wire. CoffeeScript is just a "little language".

Look at this:
wcf = require 'wcf.js'
fs = require 'fs'

binding = new wcf.WSHttpBinding
	SecurityMode: "Message"
	MessageClientCredentialType: "Certificate"	
	MessageEncoding: "Mtom"

proxy = new wcf.Proxy binding, "http://localhost:7171/Service/"
proxy.ClientCredentials.ClientCertificate.Certificate = 
	fs.readFileSync("client.pem").toString()

message = "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>
                <Header />
                  <Body>
                    <GetData xmlns='http://tempuri.org/'>
                      <value>123</value>
                    </GetData>
                  </Body>
              </Envelope>"

proxy.send message, "http://tempuri.org/IService/GetData", 
		    (message, ctx) -> console.log ctx
So while Wcf still can't make coffee, CoffeeScript sure does make these fine custom bindings!

This magic is done via Wcf.js, the first ws-* implementation for Node.js. Wcf.js is written in pure coffeescript javascript. What's next, will Microsoft build a tablet?

Published at DZone with permission of Yaron Naveh, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)