简体   繁体   English

了解Spring-WS

[英]Understanding Spring-WS

I have a project on Spring and i would like to make it a SOAP Web Service . 我在Spring上有一个项目,我想使其成为SOAP Web Service
I have entity, DAO and controller and I would prefer not to use Apache CXF. 我有实体,DAO和控制器,并且我不想使用 Apache CXF。
I read that Spring-WS is contract first. 我读到Spring-WS首先是合同。 I'm using Intellij Idea and it generated me .wsdl and .xsd files from my entity. 我正在使用Intellij Idea,它从我的实体生成了.wsdl.xsd文件。

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? 您能给我推荐一个很好的例子,还是可以帮助我理解Spring-WS到底是什么以及如何开发它的东西?

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. 啊,我最近也经历了很多相同的任务,以了解如何通过基于xsd的spring-ws发布Web服务。 I would highly recommend checking out this blog that I found Spring WS 2 Made Easy 我强烈建议您查看我发现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. 在我浏览的20多个作品中,它是最有帮助的作品之一,并且完整的资源可以轻松下载。

You can publish a web service based solely on an xsd (or wsdl). 您可以仅基于xsd(或wsdl)发布Web服务。

<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 Spring WS将在id的位置发布wsdl,对于xsd示例,它将发布在... http:// localhost:8080 / [warName] /processStuff.wsdl

Items from the xsd matching the request and response suffixes would be interpreted as wsdl operations when published. 发布时,来自xsd的与请求和响应后缀相匹配的项目将被解释为wsdl操作。

You would then need to develop a class annotated with @Endpoint that matches the operations and arguments from the xsd. 然后,您需要开发一个用@Endpoint注释的类,该类与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. 我宁愿自己写Java代码,也不愿自己写XSD。

As noted by Sean F, the dynamic wsdl generation should only be done during development as seen in the noted on Spring's page: 正如Sean F所指出的那样,动态wsdl生成仅应在开发过程中完成,如Spring页面上所述:

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. 尽管从您的XSD在运行时创建WSDL可能非常方便,但是这种方法有两个缺点。 First off, though we try to keep the WSDL generation process consistent between releases, there is still the possibility that it changes (slightly). 首先,尽管我们尝试使各个发行版之间的WSDL生成过程保持一致,但仍有可能(稍微)对其进行更改。 Second, the generation is a bit slow, though once generated, the WSDL is cached for later reference. 其次,生成有点慢,尽管一旦生成,就将WSDL缓存起来供以后参考。 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 . 然后,我们建议使用浏览器下载生成的WSDL,将其存储在项目中,并使用公开它。 This is the only way to be really sure that the WSDL does not change over time. 这是确保WSDL不会随时间变化的唯一方法。

请查看spring docs以获取所需的所有信息: http : //docs.spring.io/spring-ws/sites/2.0/

I wrote this blog three years back when I was learning Spring SOAP web-services. 三年前,当我学习Spring SOAP Web服务时,我写了这个博客 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. 该博客会照顾您,因此请记住,读者可能/可能不熟悉Web服务概念。

This is a set of two articles, one creates the SOAP web-service and hosts it. 这是一组两篇文章,其中一篇创建SOAP Web服务并将其托管。 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. 阅读完本文后,如果您仍然对基于Spring SOAP的Web服务(先合同还是后合同)有疑问,请ping me。 I will be happy to help. 我很乐意为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM