webService+Spring学习笔记

Spring所需jar包:

spring.jar

spring-webmvc.jar

 

xfire所有包

 

异常:spring xfire Cannot create mapping for java.util.List

 

wsdl不识别List,collection类型,解决方法:1、可以使用数组代替,2、创建一个接口名+.aegis.xml的文件并放到同一目录下,内容如下:

 

 

<?xml version="1.0" encoding="UTF-8"?>
<mappings>
	<mapping>
        <method name="findAllDeptInfo">
	<parameter index="0" componentType="java.lang.String" />
	<return-type  componentType="pojo.DeptInfo" />
        </method>
</mapping>
</mappings>

 wsdl不识别set类型,解决方法:创建一个实体类.aegis.xml文件并放到同一目录下,例如:

 

userInfo.java

public class userInfo{
...
private Set<RoleUser> userRoles = new HashSet<RoleUser>(0);
...
}

 对应配置文件:

 

 

<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns:my="http://my.bjvsp.tongtech.com"> 
	<mapping name="userInfo">
		<property name="userRoles" componentType="pojo.RoleUser"></property> 
	</mapping>
</mappings>

 

 

用ANT工具或命令行通过wsdl生成客户端

build.xml

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WebService是一种基于Web的远程调用技术,它使用XML格式进行数据交互。而JSON是一种轻量级的数据交换格式,比XML更加简洁和易于解析。因此,WebService和JSON的结合可以实现跨平台、跨语言的数据交互。 下面是一个使用Java中的net.sf.json库实现WebService+JSON的例子: ```java // 定义一个WebService接口 @WebService public interface HelloWorld { @WebMethod String sayHello(String name); } // 实现WebService接口 @WebService(endpointInterface = "com.example.HelloWorld") public class HelloWorldImpl implements HelloWorld { public String sayHello(String name) { return "Hello " + name + "!"; } } // 发布WebService服务 public class WebServicePublisher { public static void main(String[] args) { String url = "http://localhost:8080/HelloWorld"; Endpoint.publish(url, new HelloWorldImpl()); System.out.println("WebService服务已发布:" + url); } } // 使用JSON格式调用WebService服务 public class WebServiceClient { public static void main(String[] args) { String url = "http://localhost:8080/HelloWorld"; String name = "Alice"; JSONObject request = new JSONObject(); request.put("name", name); String response = HttpClientUtil.doPost(url, request.toString()); JSONObject result = JSONObject.fromObject(response); String message = result.getString("message"); System.out.println(message); // 输出:Hello Alice! } } ``` 上述代码中,我们定义了一个简单的HelloWorld接口和实现类,并使用Endpoint.publish()方法将其发布为WebService服务。然后,我们使用net.sf.json库将请求数据和响应数据转换为JSON格式,并使用HttpClientUtil.doPost()方法发送POST请求调用WebService服务。最后,我们将响应数据解析为JSON格式,并获取其中的message字段作为调用结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值