Java Axis2 1.6.3+JDK1.7.0_13+Tomcat7.0.65+eclipse搭建web service
2015-11-06 20:39
633 查看
安装文件下载:
jdk1.7.0_13
安装步骤参考文章:http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html
tomcat7.0.65
安装步骤参考文章:http://jingyan.baidu.com/article/870c6fc33e62bcb03fe4be90.html
axis2 1.6.3,官网http://axis.apache.org/axis2/java/core/download.cgi下载:WAR Distribution zip
下载到文件为:axis2-1.6.3-war.zip
sqljdbc4.jar
百度搜索sqljdbc,找到Microsoft JDBC Driver for SQL Server(微软官网)点开链接,建议下载sqljdbc_4.0.2206.100_enu.tar.gz,解压后把
参考文章:http://www.open-open.com/lib/view/1329999223671
http://blog.csdn.net/keenweiwei/article/details/7332261
eclipse,到官网下载即可。
安装及配置:
1,)安装Java Jdk到E:\Java\Java_Jdk1.7目录
2,)解压tomcat到E:\Java\apache-tomcat-7.0.65
3,)sqljdbc.jar文件存放路径为:E:\Java\sqljdbc\sqljdbc4.jar
4,)将axis2-1.6.3-war.zip加压,将解压出来的axis2.war文件拷贝到E:\Java\apache-tomcat-7.0.65\webapps下
5,)环境变量配置:
CLASSPATH
.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;E:\Java\sqljdbc\sqljdbc4.jar
JAVA_HOME
E:\Java\Java_Jdk1.7\jdk1.7.0_13
CATALINA_HOME
E:\Java\apache-tomcat-7.0.65
Path
追加%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
6,)安装tomcat7.0,cmd进入目录E:\Java\apache-tomcat-7.0.65\bin 执行service.bat install命令,等待安装完成双击E:\Java\apache-tomcat-7.0.65\bin\tomcat7w.exe,并运行该服务
7,)浏览器中输入地址:http:\\localhost:8080回车,如果出现tomcat首页说明环境配置成功
8,)访问地址http:\\localhost:8080\axis2出现axis2页面说明axis2安装成功
9,)解压eclipse文件,并创建桌面快捷方式。
10,)拷贝E:\Java\sqljdbc\sqljdbc4.jar到E:\Java\apache-tomcat-7.0.65\lib下
开发
1,)运行eclipse,配置运行java jdk为为当前jdk,sever为当前tomcat7.0;
2,)创建web站点(web\dynamic web project),起名为test.
3,)将E:\Java\apache-tomcat-7.0.65\workapps\axis2\WEB-INF\下的lib、conf、modules、services文件夹拷贝到test工程的WEB-INF下。
4,)清空工程WEB-INF\services\下的文件,新建目录test\META-INF\,再在WEB-INF\services\test\META-INF\下新建文件services.xml,内容填写为:
5,)修改工程下\WEB-INF\web.xml内容为:
6,)src下新建包com.dt.webservices,新建类AccountService.java
7,)新加入包E:\Java\sqljdbc\sqljdbc4.jar
8,)编辑AccountService.java为:
View Code
2,)测试调用代码:
参考文章:
axis2 1.6.3+tomcat7.0+jdk7.0+sqlserver
tomcat http://jingyan.baidu.com/article/870c6fc33e62bcb03fe4be90.html jdk http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html demo http://www.cnblogs.com/javawebsoa/archive/2013/05/19/3087234.html http://jingyan.baidu.com/article/a3761b2bbe092c1576f9aa29.html
map foreach http://blog.csdn.net/tjcyjd/article/details/11111401 客户端调用: http://m.blog.csdn.net/blog/jiqiujia/37097249 http://blog.csdn.net/yhhah/article/details/4158487
jdk1.7.0_13
安装步骤参考文章:http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html
tomcat7.0.65
安装步骤参考文章:http://jingyan.baidu.com/article/870c6fc33e62bcb03fe4be90.html
axis2 1.6.3,官网http://axis.apache.org/axis2/java/core/download.cgi下载:WAR Distribution zip
下载到文件为:axis2-1.6.3-war.zip
sqljdbc4.jar
百度搜索sqljdbc,找到Microsoft JDBC Driver for SQL Server(微软官网)点开链接,建议下载sqljdbc_4.0.2206.100_enu.tar.gz,解压后把
参考文章:http://www.open-open.com/lib/view/1329999223671
http://blog.csdn.net/keenweiwei/article/details/7332261
eclipse,到官网下载即可。
安装及配置:
1,)安装Java Jdk到E:\Java\Java_Jdk1.7目录
2,)解压tomcat到E:\Java\apache-tomcat-7.0.65
3,)sqljdbc.jar文件存放路径为:E:\Java\sqljdbc\sqljdbc4.jar
4,)将axis2-1.6.3-war.zip加压,将解压出来的axis2.war文件拷贝到E:\Java\apache-tomcat-7.0.65\webapps下
5,)环境变量配置:
CLASSPATH
.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;E:\Java\sqljdbc\sqljdbc4.jar
JAVA_HOME
E:\Java\Java_Jdk1.7\jdk1.7.0_13
CATALINA_HOME
E:\Java\apache-tomcat-7.0.65
Path
追加%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
6,)安装tomcat7.0,cmd进入目录E:\Java\apache-tomcat-7.0.65\bin 执行service.bat install命令,等待安装完成双击E:\Java\apache-tomcat-7.0.65\bin\tomcat7w.exe,并运行该服务
7,)浏览器中输入地址:http:\\localhost:8080回车,如果出现tomcat首页说明环境配置成功
8,)访问地址http:\\localhost:8080\axis2出现axis2页面说明axis2安装成功
9,)解压eclipse文件,并创建桌面快捷方式。
10,)拷贝E:\Java\sqljdbc\sqljdbc4.jar到E:\Java\apache-tomcat-7.0.65\lib下
开发
1,)运行eclipse,配置运行java jdk为为当前jdk,sever为当前tomcat7.0;
2,)创建web站点(web\dynamic web project),起名为test.
3,)将E:\Java\apache-tomcat-7.0.65\workapps\axis2\WEB-INF\下的lib、conf、modules、services文件夹拷贝到test工程的WEB-INF下。
4,)清空工程WEB-INF\services\下的文件,新建目录test\META-INF\,再在WEB-INF\services\test\META-INF\下新建文件services.xml,内容填写为:
<?xml version="1.0" encoding="UTF-8"?> <service name="AccountService"> <description> HelloWorld Service Example </description> <parameter name="ServiceClass"> com.dt.webservices.AccountService </parameter> <operation name="addUserInfo"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <operation name="modifyUserInfo"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <operation name="delUser"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <operation name="modifyPwd"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <operation name="queryUsers"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> </service>
5,)修改工程下\WEB-INF\web.xml内容为:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
6,)src下新建包com.dt.webservices,新建类AccountService.java
7,)新加入包E:\Java\sqljdbc\sqljdbc4.jar
8,)编辑AccountService.java为:
//------------------------------------------------------------------------------ // <auto-generated> // 此代码由工具生成。 // 运行时版本:4.0.30319.18408 // // 对此文件的更改可能会导致不正确的行为,并且如果 // 重新生成代码,这些更改将会丢失。 // </auto-generated> //------------------------------------------------------------------------------ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] [System.ServiceModel.ServiceContractAttribute(Namespace="http://webservices.dt.com", ConfigurationName="AccountServicePortType")] public interface AccountServicePortType { [System.ServiceModel.OperationContractAttribute(Action="urn:queryUsers", ReplyAction="urn:queryUsersResponse")] [return: System.ServiceModel.MessageParameterAttribute(Name="return")] string queryUsers(); [System.ServiceModel.OperationContractAttribute(Action="urn:addUserInfo", ReplyAction="urn:addUserInfoResponse")] [return: System.ServiceModel.MessageParameterAttribute(Name="return")] string addUserInfo(string userInfos); [System.ServiceModel.OperationContractAttribute(Action="urn:modifyPwd", ReplyAction="urn:modifyPwdResponse")] [return: System.ServiceModel.MessageParameterAttribute(Name="return")] string modifyPwd(string userInfos); [System.ServiceModel.OperationContractAttribute(Action="urn:modifyUserInfo", ReplyAction="urn:modifyUserInfoResponse")] [return: System.ServiceModel.MessageParameterAttribute(Name="return")] string modifyUserInfo(string userInfos); [System.ServiceModel.OperationContractAttribute(Action="urn:delUser", ReplyAction="urn:delUserResponse")] [return: System.ServiceModel.MessageParameterAttribute(Name="return")] string delUser(string userIDs); } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] public interface AccountServicePortTypeChannel : AccountServicePortType, System.ServiceModel.IClientChannel { } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] public partial class AccountServicePortTypeClient : System.ServiceModel.ClientBase<AccountServicePortType>, AccountServicePortType { public AccountServicePortTypeClient() { } public AccountServicePortTypeClient(string endpointConfigurationName) : base(endpointConfigurationName) { } public AccountServicePortTypeClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public AccountServicePortTypeClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public AccountServicePortTypeClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) { } public string queryUsers() { return base.Channel.queryUsers(); } public string addUserInfo(string userInfos) { return base.Channel.addUserInfo(userInfos); } public string modifyPwd(string userInfos) { return base.Channel.modifyPwd(userInfos); } public string modifyUserInfo(string userInfos) { return base.Channel.modifyUserInfo(userInfos); } public string delUser(string userIDs) { return base.Channel.delUser(userIDs); } }
View Code
2,)测试调用代码:
static void Main(string[] args) { using (AccountServicePortTypeClient client = new AccountServicePortTypeClient("AccountServiceHttpSoap11Endpoint")) { string addUserInfoParameter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; addUserInfoParameter += "<accounts>"; addUserInfoParameter += " <account>"; addUserInfoParameter += " <accId>test22</accId>"; addUserInfoParameter += " <userPassword>z3ux4rpW0H3QbY47pjZa6w==</userPassword>"; addUserInfoParameter += " <name>test22</name>"; addUserInfoParameter += " <description>描述</description>"; addUserInfoParameter += " <email>test22@catt.cn</email>"; addUserInfoParameter += " <nation>汉族</nation>"; addUserInfoParameter += " </account>"; addUserInfoParameter += " <account>"; addUserInfoParameter += " <accId>test23</accId>"; addUserInfoParameter += " <userPassword>z3ux4rpW0H3QbY47pjZa6w==</userPassword>"; addUserInfoParameter += " <name>test23</name>"; addUserInfoParameter += " <description>描述</description>"; addUserInfoParameter += " <email>test23@catt.cn</email>"; addUserInfoParameter += " <nation>汉族</nation>"; addUserInfoParameter += " </account>"; addUserInfoParameter += "</accounts>"; Console.WriteLine("addUserInfo:{0}", client.addUserInfo(addUserInfoParameter)); string modifyUserInfoParameter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; modifyUserInfoParameter += "<accounts>"; modifyUserInfoParameter += " <account>"; modifyUserInfoParameter += " <accId>test22</accId>"; modifyUserInfoParameter += " <userPassword>z3ux4rpW0H3QbY47pjZa6w==</userPassword>"; modifyUserInfoParameter += " <name>test232</name>"; modifyUserInfoParameter += " <description>描述</description>"; modifyUserInfoParameter += " <email>test232@catt.cn</email>"; modifyUserInfoParameter += " <nation>汉族</nation>"; modifyUserInfoParameter += " </account>"; modifyUserInfoParameter += " <account>"; modifyUserInfoParameter += " <accId>test23</accId>"; modifyUserInfoParameter += " <userPassword>z3ux4rpW0H3QbY47pjZa6w==</userPassword>"; modifyUserInfoParameter += " <name>test233</name>"; modifyUserInfoParameter += " <description>描述</description>"; modifyUserInfoParameter += " <email>test233@catt.cn</email>"; modifyUserInfoParameter += " <nation>汉族</nation>"; modifyUserInfoParameter += " </account>"; modifyUserInfoParameter += "</accounts>"; Console.WriteLine("modifyUserInfo:{0}", client.modifyUserInfo(modifyUserInfoParameter)); string modifyParameter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; modifyParameter += "<accounts>"; modifyParameter += " <account>"; modifyParameter += " <accId>admin</accId>"; modifyParameter += " <userPassword>z3ux4rpW0H3QbY47pjZa6w==</userPassword>"; modifyParameter += " </account>"; modifyParameter += "</accounts>"; Console.WriteLine("modifyPwd:{0}", client.modifyPwd(modifyParameter)); string delUserParameter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; delUserParameter += "<accounts>"; delUserParameter += " <accId>test</accId>"; delUserParameter += " <accId>admin</accId>"; delUserParameter += "</accounts>"; Console.WriteLine("delUser:{0}", client.delUser(delUserParameter)); Console.WriteLine("queryUsers:{0}", client.queryUsers()); } Console.ReadKey(); }
参考文章:
axis2 1.6.3+tomcat7.0+jdk7.0+sqlserver
tomcat http://jingyan.baidu.com/article/870c6fc33e62bcb03fe4be90.html jdk http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html demo http://www.cnblogs.com/javawebsoa/archive/2013/05/19/3087234.html http://jingyan.baidu.com/article/a3761b2bbe092c1576f9aa29.html
map foreach http://blog.csdn.net/tjcyjd/article/details/11111401 客户端调用: http://m.blog.csdn.net/blog/jiqiujia/37097249 http://blog.csdn.net/yhhah/article/details/4158487
相关文章推荐
- 阿里云服务器AES搭建tomcat环境
- 如何在Linux下安装启动多个Tomcat
- eclipse tomcat maven项目布署的一些问题解决方法
- tomcat配置项目的图片路径不在项目下的处理
- tomcat catalina.sh JAVA_OPTS参数说明与配置
- java入门--配置tomcat
- Tomcat的配置文件 —— server.xml
- tomcat配置
- tomcat部署项目Add and Remove找不到项目
- tomcat warn:The APR based apache tomcat native library failed to load
- windows下tomcat和nginx负载均衡的简单配置!
- tomcat 使用问题
- nginx和tomcat负载均衡后session无法共享的解决方案
- web tomcat 7可以运行,部署weblogic10.3不行
- Tomcat启动报错,The CATALINA_HOME environment variable is not defined correctly
- Eclipse导入Tomcat源码
- Tomcat启用Gzip压缩
- Tomcat7源码的环境搭建
- apache2.2.25+mod_jk-apache-2.2.2.so+apache-tomcat-7.0.56集群
- Tomcat Cannot assign requested address: JVM_Bind 非端口占用冲突