- 浏览: 24407 次
- 性别:
- 来自: 合肥
最近访客 更多访客>>
文章分类
最新评论
-
光影门徒:
总结的很不错,谢谢了
JavaScript在IE和Firefox下的兼容性问题 -
zy2419:
总结的很好啊
JavaScript在IE和Firefox下的兼容性问题 -
ccyingfu:
Firefox支持innerHTML呀....是哪个版本不支持 ...
JavaScript在IE和Firefox下的兼容性问题 -
JasonChi:
SF 学习
JavaScript在IE和Firefox下的兼容性问题 -
qbq:
SampleServerImpl Server = new S ...
java远程处理
首先介绍一下,这个应用的业务逻辑,很简单,就是客户端向服武器端发送一个用户名,然后服务器端根据用户名返回,该人的详细信息.
1):首先写个 服武器端的service
该类的代码如下:
2):用上边的服务端的service 生成 AxisTest.wsdl文件 用eclipse的插件生成代码的过程我就部说了.
这个文件的代码如下:
3):写个客户端的代码用来和服务器端通信:代码如下:
4):在联合上述客户端和服务器端通信的代码中还有两个类,他们用来携带客户端向服务器端发送的消息和服务器端根据客户端发送来的消息返回的消息.代码如下:
5):还有一个比较重要的文件 就是services.xml
代码如下:
到现在代码都已经完成了用eclipse的打包工具,把它打成包就可以发布了,运行客户端程序就可以在控制台和tomcat控制台看到结果了,注意服务器端的信息只打印在tomcat控制台上.在eclipse的控制台看到的信息是客户端和服务器发回的信息.
特别注意的是,如果在编译中出现问题,很可能是jar包版本不同导致的.
1):首先写个 服武器端的service
该类的代码如下:
package com.neusoft.axis.service; import com.neusoft.axis.common.AxisClientRequestInfo; import com.neusoft.axis.common.AxisServiceResponseInfo; public class AxisServiceResponse { public AxisServiceResponseInfo axisServiceReturnPersonInfo(AxisClientRequestInfo clientrequest) { AxisServiceResponseInfo axisserviceresponseinfo = new AxisServiceResponseInfo(); String name = clientrequest.getName(); if(name.equals("许兆光")) { axisserviceresponseinfo.setAge("25"); axisserviceresponseinfo.setDegree("本科"); axisserviceresponseinfo.setSex("男"); } else if(name.equals("葛祥平")) { axisserviceresponseinfo.setAge("27"); axisserviceresponseinfo.setDegree("研究生"); axisserviceresponseinfo.setSex("男"); } else { axisserviceresponseinfo.setAge(""); axisserviceresponseinfo.setDegree(""); axisserviceresponseinfo.setSex(""); System.out.println("客户端没有发送姓名到服务端!"); } if(name.equals("")) { return axisserviceresponseinfo; } System.out.println("客户端发送来的姓名是:"+name); System.out.println("下边是服武器端根据客户端发送来姓名得到的该人的详细信息:"); System.out.println("姓名=========="+name); System.out.println("年龄=========="+axisserviceresponseinfo.getAge()); System.out.println("学位=========="+axisserviceresponseinfo.getDegree()); System.out.println("性别=========="+axisserviceresponseinfo.getSex()); return axisserviceresponseinfo; } }
2):用上边的服务端的service 生成 AxisTest.wsdl文件 用eclipse的插件生成代码的过程我就部说了.
这个文件的代码如下:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns1="http://AxisServiceResponse.service.axis.neusoft.com/types" xmlns:ns="http://AxisServiceResponse.service.axis.neusoft.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://AxisServiceResponse.service.axis.neusoft.com"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:stn_1="http://common.axis.neusoft.com/xsd" targetNamespace="http://common.axis.neusoft.com/xsd" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <xs:element type="stn_1:AxisClientRequestInfo" name="AxisClientRequestInfo" /> <xs:complexType name="AxisClientRequestInfo"> <xs:sequence> <xs:element type="xs:string" name="name" /> </xs:sequence> </xs:complexType> <xs:element type="stn_1:AxisServiceResponseInfo" name="AxisServiceResponseInfo" /> <xs:complexType name="AxisServiceResponseInfo"> <xs:sequence> <xs:element type="xs:string" name="age" /> <xs:element type="xs:string" name="degree" /> <xs:element type="xs:string" name="sex" /> </xs:sequence> </xs:complexType> <xs:complexType name="AxisClientRequestInfo"> <xs:sequence> <xs:element type="xs:string" name="name" /> </xs:sequence> </xs:complexType> <xs:complexType name="AxisServiceResponseInfo"> <xs:sequence> <xs:element type="xs:string" name="age" /> <xs:element type="xs:string" name="degree" /> <xs:element type="xs:string" name="sex" /> </xs:sequence> </xs:complexType> </xs:schema> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:types="http://AxisServiceResponse.service.axis.neusoft.com/types" xmlns:stn_3="http://common.axis.neusoft.com/xsd" targetNamespace="http://AxisServiceResponse.service.axis.neusoft.com/types" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <xs:import namespace="http://common.axis.neusoft.com/xsd" /> <xs:element name="axisServiceReturnPersonInfo"> <xs:complexType> <xs:sequence> <xs:element type="stn_3:AxisClientRequestInfo" name="clientrequest" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="axisServiceReturnPersonInfoResponse"> <xs:complexType> <xs:sequence> <xs:element type="stn_3:AxisServiceResponseInfo" name="return" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </wsdl:types> <wsdl:message name="axisServiceReturnPersonInfoMessage"> <wsdl:part element="ns1:axisServiceReturnPersonInfo" name="part1" /> </wsdl:message> <wsdl:message name="axisServiceReturnPersonInfoResponseMessage"> <wsdl:part element="ns1:axisServiceReturnPersonInfoResponse" name="part1" /> </wsdl:message> <wsdl:portType name="AxisServiceResponsePortType"> <wsdl:operation name="axisServiceReturnPersonInfo"> <wsdl:input message="ns:axisServiceReturnPersonInfoMessage" /> <wsdl:output message="ns:axisServiceReturnPersonInfoResponseMessage" /> </wsdl:operation> </wsdl:portType> <wsdl:binding type="ns:AxisServiceResponsePortType" name="AxisServiceResponseSOAP11Binding"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="axisServiceReturnPersonInfo"> <soap:operation style="document" soapAction="urn:axisServiceReturnPersonInfo" /> <wsdl:input> <soap:body namespace="http://AxisServiceResponse.service.axis.neusoft.com" use="literal" /> </wsdl:input> <wsdl:output> <soap:body namespace="http://AxisServiceResponse.service.axis.neusoft.com" use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding type="ns:AxisServiceResponsePortType" name="AxisServiceResponseSOAP12Binding"> <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="axisServiceReturnPersonInfo"> <soap12:operation style="document" soapAction="urn:axisServiceReturnPersonInfo" /> <wsdl:input> <soap12:body namespace="http://AxisServiceResponse.service.axis.neusoft.com" use="literal" /> </wsdl:input> <wsdl:output> <soap12:body namespace="http://AxisServiceResponse.service.axis.neusoft.com" use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="AxisServiceResponse"> <wsdl:port binding="ns:AxisServiceResponseSOAP11Binding" name="AxisServiceResponseSOAP11port"> <soap:address location="http://localhost:8080/axis2/services/AxisServiceResponse" /> </wsdl:port> <wsdl:port binding="ns:AxisServiceResponseSOAP12Binding" name="AxisServiceResponseSOAP12port"> <soap12:address location="http://localhost:8080/axis2/services/AxisServiceResponse" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
3):写个客户端的代码用来和服务器端通信:代码如下:
package com.neusoft.axis.client; import javax.xml.namespace.QName; import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.rpc.client.RPCServiceClient; import com.neusoft.axis.common.AxisClientRequestInfo; import com.neusoft.axis.common.AxisServiceResponseInfo; public class AxisClientRequest { public static void main(String[] args) throws AxisFault { System.out.println("==========客户端发送一个用户名,下边是服武器端根据用户名返回的该人的详细信息"); System.out.println("==========开始向服武器端发送数据"); RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); EndpointReference targetEPR = new EndpointReference("http://localhost:8888/axis2/services/AxisTest"); options.setTo(targetEPR); QName sendPersonInfo = new QName("http://AxisServiceResponse.service.axis.neusoft.com/types", "axisServiceReturnPersonInfo"); AxisClientRequestInfo axisclientrequestinfo = new AxisClientRequestInfo(); axisclientrequestinfo.setName("许兆光"); System.out.println("==========客户端发送的姓名是:"+axisclientrequestinfo.getName()); Class[] returnTypes = new Class[] { AxisServiceResponseInfo.class }; Object[] opSendInfo = new Object[] { axisclientrequestinfo}; System.out.println("==========开始请求服武器端方法:"+"axisServiceReturnPersonInfo"); Object[] response = serviceClient.invokeBlocking(sendPersonInfo, opSendInfo, returnTypes); System.out.println("==========客户端请求服务端方法成功!"); AxisServiceResponseInfo result = (AxisServiceResponseInfo) response[0]; System.out.println("==========下边是从服武器返回"+axisclientrequestinfo.getName()+"的个人信息是:"); System.out.println("==========年龄"+result.getAge()); System.out.println("==========学历"+result.getDegree()); System.out.println("==========性别"+result.getSex()); } }
4):在联合上述客户端和服务器端通信的代码中还有两个类,他们用来携带客户端向服务器端发送的消息和服务器端根据客户端发送来的消息返回的消息.代码如下:
package com.neusoft.axis.common; public class AxisClientRequestInfo { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } package com.neusoft.axis.common; public class AxisServiceResponseInfo { private String sex; private String age; private String degree; public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getDegree() { return degree; } public void setDegree(String degree) { this.degree = degree; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } }
5):还有一个比较重要的文件 就是services.xml
代码如下:
<service name="AxisTest" scope="application" targetNamespace="http://AxisServiceResponse.service.axis.neusoft.com/types"> <description>Security Joint Defence Service</description> <parameter name="ServiceClass" locked="false"> com.neusoft.axis.service.AxisServiceResponse </parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </messageReceivers> <schema schemaNamespace="http://AxisServiceResponse.service.axis.neusoft.com/types" /> </service>
到现在代码都已经完成了用eclipse的打包工具,把它打成包就可以发布了,运行客户端程序就可以在控制台和tomcat控制台看到结果了,注意服务器端的信息只打印在tomcat控制台上.在eclipse的控制台看到的信息是客户端和服务器发回的信息.
特别注意的是,如果在编译中出现问题,很可能是jar包版本不同导致的.
发表评论
-
Java 面试经典 04--Spring、Hibernate
2010-10-13 12:56 2551spring:依赖注入,事务管理,JDBC数据访问,sp ... -
Java 面试经典 02--Jquery
2010-10-13 12:51 1669一、Jquery测试题 下面哪种不是jquery的选择器?( ... -
Java 面试经典 01--jsp
2010-10-13 12:49 2512Jsp 1,当浏览器第二次(同一会话)访问以下jsp网页时的输 ... -
WebService基础概要
2010-02-25 14:19 1200一、 Web Service的简介 1 ... -
java反射机制
2010-02-25 13:49 854Reflection 是 Java 程序开发语言的特征之一,它 ... -
java远程处理
2010-02-25 13:42 809Java远程方法调用(RMI)提 ... -
java方法概述
2010-02-25 01:13 749检查参数的有效性 非公有的方法我们应该用断言的方法来检查它的 ... -
java异常处理
2010-02-25 01:09 839只针对不正常的条件才使用异常 异常只应该被用于不正常的条件 ... -
类和接口
2010-02-25 00:50 865使类和成员的可访问能力最小化 public表示这个类在任何范围 ... -
Java通用方法
2010-02-25 00:46 744Object中的所有非final方法(equals 、hash ...
相关推荐
部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)部署WebService(eclipse-axis2)
axis2-idea-plugin-1.7.9
axis2-1.5.1-bin.zip axis2-1.5.1-war.zip webservice部署axis所需要是包
axis2-eclipse-codegen-plugin-1.6.2.zip和axis2-eclipse-service-plugin-1.6.2.zip,解压即可使用
目前axis2最高版本是2.0以上的版本,但是eclipse和myeclipse都不支持,无奈只能使用低版本的插件1.6.3;经实验,可以安装成功; 安装方法:右键解压到当前文件夹,Copy解压的文件到eclipse安装目录dropins下,重启...
共四个文件,都是最先版的,希望可以帮助大家。axis2-eclipse-service-archiver-wizard和axis2-eclipse-codegen-wizard和axis2-1.6.1-bin和axis2-1.6.1-war
axis2-kernel-1.3.jar axis2-kernel-1.3.jar
内容概要:利用Axis2开发WebService服务
webService 生成插件axis2- idea-plugin-1.7.8
axis2c-bin-1.6.0-linux.tar.gz axis2c-bin-1.6.0-win32.zip axis2c-src-1.6.0.tar.gz axis2c-src-1.6.0.zip 加md5
axis2-std-1.0-bin.zip与axis2.war axis2-std-1.0-bin.zip与axis2.war
axis2 webservice 服务端jar包: -->axis2-kernel-1.6.1.jar -->axis2-spring-1.6.1.jar -->axis2-transport-http-1.6.1.jar -->XmlSchema-1.4.7.jar -->wsdl4j-1.6.2.jar -->axiom-api-1.2.12.jar -->axiom...
绝对可以用,里面配有myeclipse10安装AXIS2插件的步骤,希望大家工作愉快,谢谢,给好评哦
axis2-1.6.0-bin和axis2-1.6.0-war相关资源
axis2-webservice axis2-webservice axis2-webservice axis2-webservice axis2-webservice
Axis2(WebService)经典教程,详细讲述了如何用axis2实现webservice,由浅入深,配合实例。
包括两个工具包axis2-1.4.1-bin.zip,和axis2-1.4.1-war.zip
Axis2-1.6.2-bin和Axis2-1.6.2-war
axis2-1.5.4-bin axis2-1.5.4-war
axis2-eclipse-codegen-plugin-1.6.0和axis2-eclipse-service-plugin-1.6.0有关jar包下载,解压后直接将这两个jar包放到eclips下的plugins目录下,重启eclipse即可