qiGuar
qiGuar

Reputation: 1804

Understanding Spring-WS

I have a project on Spring and i would like to make it a SOAP Web Service.
I have entity, DAO and controller and I would prefer not to use Apache CXF.
I read that Spring-WS is contract first. I'm using Intellij Idea and it generated me .wsdl and .xsd files from my entity.

If I delete my entity and continue, will it count as contract first?
Could you please suggest me a nice example or something that will help me understand what exactly is Spring-WS and how to develop it?

Upvotes: 0

Views: 5834

Answers (3)

Erich
Erich

Reputation: 1603

Ahh, I have recently gone through much of the same quest to find out how to publish a web service through spring-ws based on an xsd. I would highly recommend checking out this blog that I found Spring WS 2 Made Easy

Of the 20+ that I looked through it was one of the most helpful and has the complete source easily downloadable.

You can publish a web service based solely on an xsd (or wsdl).

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:sws="http://www.springframework.org/schema/web-services"
    xsi:schemaLocation="http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/web-services                          
        http://www.springframework.org/schema/web-services/web-services-2.0.xsd">

<!-- To detect @Endpoint -->        
<sws:annotation-driven />

<!-- publish wsdl from xsd (use during development)-->
<sws:dynamic-wsdl
    id="processStuff"
    portTypeName="MyService"
    locationUri="/myService"
    requestSuffix="Request"
    responseSuffix="Response"
    targetNamespace="http://mycompany.com/dostuff">
    <sws:xsd location="/WEB-INF/xsds/myschema.xsd"/>
</sws:dynamic-wsdl>

<!-- publish static wsdl (better for production deployments)-->
<sws:static-wsdl id="orders" location="/WEB-INF/wsdl/orders.wsdl"/>

</beans>

Spring WS will publish a wsdl at the location of the id, for the xsd example this would publish at... http://localhost:8080/[warName]/processStuff.wsdl

Items from the xsd matching the request and response suffixes would be interpreted as wsdl operations when published.

You would then need to develop a class annotated with @Endpoint that matches the operations and arguments from the xsd.

Small example:

@Endpoint
public class MyWebService {

    @PayloadRoot(namespace = "http://mycompany.com/dostuff", localPart = "SomeRequest")
    @ResponsePayload
    public SomeResponse getSomething(@RequestPayload SomeRequest something) {
        return new SomeResponse();
    }
}

I would say it's contract first, you just wrote the contract through code, which I have done myself before. I would rather write Java code than an xsd personally.

As noted by Sean F, the dynamic wsdl generation should only be done during development as seen in the noted on Spring's page:

Caution

Even though it can be quite handy to create the WSDL at runtime from your XSDs, there are a couple of drawbacks to this approach. First off, though we try to keep the WSDL generation process consistent between releases, there is still the possibility that it changes (slightly). Second, the generation is a bit slow, though once generated, the WSDL is cached for later reference. It is therefore recommended to only use during the development stages of your project. Then, we recommend to use your browser to download the generated WSDL, store it in the project, and expose it with . This is the only way to be really sure that the WSDL does not change over time.

Upvotes: 3

dharam
dharam

Reputation: 8096

I wrote this blog three years back when I was learning Spring SOAP web-services. Please visit the blog

This blog takes care and is reason keeping in mind that the reader may/may not be familiar with the Web-service concepts.

This is a set of two articles, one creates the SOAP web-service and hosts it. The other article writes a client for the same.

After reading this if you still have questions regarding Spring SOAP based web-service (Contract first or Contract Last) please ping me. I will be happy to help.

Upvotes: 0

Pratik Shelar
Pratik Shelar

Reputation: 3212

Please check out spring docs for all the info that you need: http://docs.spring.io/spring-ws/sites/2.0/

Upvotes: 0

Related Questions