Search code examples
web-servicessoapxml-rpcrpc

Has any language or library found a way to implement a SOAP client without tons and tons of generated code?


I come from the .NET and Java world, and my impression of SOAP is that it always involves lots and lots of generated boilerplate code. Is this a priori necessary? Or have other languages or libraries found a way to do away with this?


Solution

  • With Spring WebServices you can end up with JAXB generated classes (from XSD) only and use your own implementation which just uses these classes as method parameters and endpoint types.

    SOAP itself can be seen as cumbersome protocol which requires expensive/heavyweight tools. It can also be seen as a thin wrapper of XML payloads which has great advantage - WSDL as a description language (which can also be seen both as heavy or as ubiquitous) which describes operations and parameters.

    Back to Spring Web Services, here's the roadmap:

    • you have only XSD
    • you use XJC (or some maven plugin) to generate classes
    • you write your own endpoint with methods which use these classes as parameters

    here's sample endpoint:

    @PayloadRoot(localPart = "myMethod", namespace = "http://example.com")
    @ResponsePayload
    public MyResult myMethod(@RequestPayload MyRequest req)
    {
    }
    

    I've written many big web services and writing by hand ~50 such methods is much more pleasant and effective then relying on generated code.