webService 能够将应用程序转换成网络应用程序。是简单的可共同操做的消息收发框架。java
基本的webService平台是 XML 和 HTTP。web
HTTP 是最经常使用的互联网协议;spring
XML 是 webService 的基础,由于能够用于不一样平台和编程语言之间。编程
webService平台的元素:spring-mvc
SOAP(简易对象访问协议);网络
UDDI(通用描述、发现、整合);mvc
WSDL(web service 描述语言);框架
webService 有两种类型的应用maven
1)可重复使用的应用程序组件:有些功能是不一样应用程序经常用到的,好比:天气预报。webService能够把应用程序组件当作服务来提供;编程语言
2)链接现有软件:经过为不一样程序提供一种连接其数据的途径,解决协同办公的问题。
简单程序:
建立一个service 的 web service project工程 :
package com.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService //将类标注为webService
public class Test {
@WebMethod //标注客户端调用的方法
public String getString (String name){
return name.toUpperCase();
}
public static void main(String[] args) {
//发布到服务端 参数1:网络协议+ip+端口号(不能被占用)+上下文根+调用方法 参数2:new一个本类的实例
Endpoint.publish("http://localhost:8085/Test", new Test());
//标志着编译成功结束 可不写
System.out.println("OK");
}
}
//配置文件我如今尚未搞明白 若是不配配置测试地址就无响应
配置一个xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 注册组件扫描器 -->
<context:component-scan base-package="com.service" />
</beans>
测试地址:http://localhost:8085/Test?wsdl
利用 webService soapUI 4.5.2软件 连接http://localhost:8085/service/Test 自动生成应用服务
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.com/">
<soapenv:Header/>
<soapenv:Body>
<ser:getString>
<!--Optional:-->
<arg0>yyyy</arg0> //<arg0>?</arg0> 原始显示是? 为需求参数
</ser:getString>
</soapenv:Body>
</soapenv:Envelope>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStringResponse xmlns:ns2="http://service.com/">
<return>YYYY</return> //<return>?</return> 原始显示是? 为处理结果
</ns2:getStringResponse>
</S:Body>
</S:Envelope>
二、命令提示窗口执行生成命令。
先建立一个client 的web service project 工程
打开 命令窗口 输入
格式:wsimport -s "src目录" -p “生成类所在包名” -keep “wsdl发布地址”
1)"src目录"地址不可含空格
2)“wsdl发布地址”不要漏了“?wsdl”
效果:
wsimport -s E:\WorkSpace\maven\client\src -p com.client -keep http://localhost:8085/Test?wsdl
正在解析 WSDL...
正在生成代码...
正在编译代码...
刷新项目就能够看到生成的client代码
可是client 客户端代码会有乱码问题目前尚未解决