Spring-WS(二)-入门

本文是Spring-WS系列的第二篇,主要介绍如何处理WebService请求。SpringWS根据Schema生成WSDL,利用MyEclipse创建请求和响应类。通过@Endpoint、@PayloadRoot等注解实现请求接收和响应。示例代码展示了不同处理方式,同时更新配置文件以扫描注解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    官方帮助手册:http://docs.spring.io/spring-ws/site/reference/html/tutorial.html

    接着《Spring-WS(一)-环境搭建》所搭建的服务,运行项目访问地址:

http://localhost:8080/Spring-WS-Demo-01/service/UserService.wsdlSpringWS会根据我们定义的Schema来生成wsdl。那这篇文章就继续开展我们的后台处理逻辑,究竟SpringWS对于Web Service请求是如何处理的?过于细节的东西就不详细说了,后续的博客都会提到,现在先把大概的脉络搭建起来。

一、根据SpringWS生成的WSDL,服务端根据接口来定义AddRequest.java,AddResponse.java等文件,但是这些工作是可以交给MyEclipse去生成的,可以通过NEW->“Web Service Client”,不清楚的可以百度。虽然MyEclipse会自动帮我们生成很多文件,但是用到的就那几个,分别是AddRequest,AddResponse,GetUserByUserNameRequest,GetUserByUserNameResponse,User 如下:

package ws.user.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import ws.user.endpoint.UserServiceEndpoint;

/**
 * <p>
 * Java class for anonymous complex type.
 * 
 * <p>
 * The following schema fragment specifies the expected content contained within
 * this class.
 * 
 * <pre>
 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <all>
 *         <element ref="{http://localhost/ws/UserService}User"/>
 *       </all>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {

})
@XmlRootElement(name = "AddRequest", namespace=UserServiceEndpoint.USER_SERVICE_NAMESPACE)
public class AddRequest {

	@XmlElement(name = "User", namespace = "http://localhost/ws/UserService", required = true)
	protected User user;

	/**
	 * Gets the value of the user property.
	 * 
	 * @return possible object is {@link User }
	 * 
	 */
	public User getUser() {
		return user;
	}

	/**
	 * Sets the value of the user property.
	 * 
	 * @param value
	 *            allowed object is {@link User }
	 * 
	 */
	public void setUser(User value) {
		this.user = value;
	}

}

package ws.user.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import ws.user.endpoint.UserServiceEndpoint;

/**
 * <p>
 * Java class for anonymous complex type.
 * 
 * <p>
 * The following schema fragment specifies the expected content containe
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值