Shoap: SOAP in Haskell
This module provides a very basic way to send SOAP messages
> module Network.Soap where
Curl is used to send the messages. This module is basically the curl post function with some stuff set by default
> import Network.Curl
soapMessage takes two strings, the header and the body of a SOAP message and wraps them in the appropriate XML. To get a well formed SOAP message the header and the body must be XML fragments. This is not checked.
> soapMessage header body = "<?xml version=\"1.0\"?><env:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><env:Header>"++header++"</env:Header><env:Body>"++body++"</env:Body></env:Envelope>"
soapPost posts a message to a URL using appropriate headers
> soapPost url message = initialize >>= \ h -> do > setopt h (CurlVerbose False)
Setting the SOAPAction header is required by the AdWords API (the service that motivated me to make this module) but it doesn’t seem to matter what the contents is. This might need changing
> setopt h (CurlHttpHeaders ["SOAPAction: Shoap"]) > setopt h (CurlPostFields message) > setopt h (CurlCookieJar "cookies") > setopt h (CurlURL url) > perform h > return ()