deployment "http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" <!-- globalConfiguration 标签内容为系统默认 无需更改à
<globalConfiguration"adminPassword" value="admin"/>
"attachments.Directory" "./attachments""attachments.implementation"
"org.apache.axis.attachments.AttachmentsImpl""sendXsiTypes" "true""sendMultiRefs" "sendXMLDeclaration" "axis.sendMinimizedElements" requestFlowhandler type="java:org.apache.axis.handlers.JWSHandler""scope" "session"handler"request""extension" ".jwr">
</"LocalResponder"
"java:org.apache.axis.transport.local.LocalResponder"/>
"URLMapper"
"java:org.apache.axis.handlers.http.URLMapper""Authenticate"
"java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
<!—service 标签是需要配置的 -à
—name 是url中需要的参数 -"axisTest" provider="java:RPC" —allowedMethods 的value值是方法名 可以写*-à
"allowedMethods" "*"/>
—className的value值是类路径-"className" "com.Axis"—wsdlTargetNamespace的wsdl文件中TargetNamespace的值-"wsdlTargetNamespace" "http://service.impl.tdi.taikang.tivoli.ibm.com/" 此处很重要,若方法需要传实体类,则配置此处-à
beanMapping qname="myNS:Userxmlns:myNS="urn:BeanService" languageSpecificType="java:com.User"/>
>
默认-à
transport "http""URLMapper""java:org.apache.axis.handlers.http.HTTPAuthHandler"transport"local"responseFlow"LocalResponder"deployment 第五步,部署,同上。
5. AXIS1客户端调用
此处调用方式为axis1的调用,需要传递的参数可以是字符串或实体类,字符串方式:
Service service = new Service();
Call call = (Call) service.createCall();
//wsdl地址
call.setTargetEndpointAddress(new URL(wsdlUrl));
//设定调用3分钟不返回则超时
call.setTimeout(new Integer(180000));
//命名空间(wsdl文件中的targetNameSpace属性值) 以及方法名
call.setOperationName(new QName("http://com", "sayHello"));
//参数类型
call.addParameter("name",XMLType.XSD_STRING,ParameterMode.IN);
//返回值类型
call.setReturnType(XMLType.XSD_STRING);
//参数值
String retXML2 = (String) call.invoke( new Object[] { "yczhang" });
System.out.println( retXML2);
实体类方式(调用axis2的接口有点问题):
UserEntity userEntry = new UserEntity();
userEntry.setId("yczhang");
userEntry.setName("yczhang");
Service service = new Service();
Call call = (Call) service.createCall();
"sayHelloToUser"));
//注册SimpleObject的序列化类型
QName qn = "urn:BeanService",0);">UserEntity");
call.registerTypeMapping(UserEntity.class,qn, new BeanSerializerFactory(UserEntity.new BeanDeserializerFactory(UserEntity. //参数类型(可省略)
call.addParameter("requestParam", org.apache.axis.encoding.XMLType.XSD_ANYTYPE,192);">XSD_BOOLEAN);
Boolean retXML1 = (Boolean) call.invoke( new Object[] { userEntry });
System.out.println( retXML1);
注意,实体类方式,当调用的是由axis2方式所发布的接口时,容易出现问题,表现在所传递的实体类的属性内容为null,但在该实体类内新建一属性传如该值时,却有值。应该是axis1对axis2的不兼容问题。并且调用axis2的接口时,需要在客户端写出namespace,即:
//call.setOperationName(new QName("http://localhost:9080/WS_Axis/services/axisTest","sayHelloToUser"));
该种调用方式对于axis1的接口没问题。泰康项目最终使用的是axis1发布的接口,并使用该种方式调用的。
static void main(String[] args) throws ServiceException,MalformedURLException,RemoteException { String wsdlUrl = "http://localhost:9080/WS_Axis/services/axisTest?wsdl";
//实体类
User user = new User();
user.setId("1");
user.setAdd("test");
user.setName("test");
user.setPath("test");
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(wsdlUrl));
//设定调用3分钟不返回则超时
call.setTimeout(//call.setOperationName(new QName("http://localhost:9080/WS_Axis/services/axisTest","sayHelloToUser"));
//注册SimpleObject的序列化类型(urn:BeanService在wsdd文件内有配置)
QName qn = "urn:BeanService",255);">"User");
call.registerTypeMapping(User.new BeanSerializerFactory(User.new BeanDeserializerFactory(User. //方法名
call.setOperationName("sayHelloToUser");
//“user”是接口服务端方法体中的实体类所声明的变量名(”say(User user))
call.addParameter("userIN);
//返回值类型
call.setReturnType(XMLType.XSD_STRING);
System.out.println( call.invoke( new Object[] { user }));
}
6. AXIS2客户端调用
所需jar包:
具体代码:
class RPClient { throws AxisFault {
try {
//实体类
UserEntity ue = new UserEntity();
ue.setId("123");
ue.setAddress("test");
ue.setMail("123");
ue.setName("yczhang");
RPCServiceClient client = new RPCServiceClient();
Options options = client.getOptions();
String url = "http://localhost:9080/WS_Axis2/services/axisDemo?wsdl";
EndpointReference end = new EndpointReference(url);
options.setTo(end);
Object[] obj = new Object[] { ue };
Class<?>[] classes = new Class[] { Boolean.class };
//命名空间 方法名
QName qname = "sayHelloToUser");
System.out.println(client.invokeBlocking(qname,obj,classes)[0]);
} catch (AxisFault e) {
e.printStackTrace();
}
}
注意 该种方式缺点是客户端实体类路径即包名必须与服务端实体类路径相同!!!但该方式可以调任何方式编写的接口!!!!
7. CXF客户端调用
使用axis、axis2客户端调用cxf接口会有问题,建议使用cxf自身客户端调用或者使用webservice Client 自动生成客户端方式
所需的jar包:
功能代码:
class TT { void main(String[] args) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://10.137.138.11:9080/WS_CXF/webservice/sendServie?wsdl");
try {
//此处http://service.com/需要指向接口路径而非实现类
System.out.println(client.invoke("http://service.com/",255);">"sendOA"),test")[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
}
注意:若运行程序时报错“JAXB 2.0 API ….. endorsed”则需要将以下jar包放入jdk lib和jre lib
重启exlipse即可。
8. Web Service Client客户端调用
右键项目:
调用代码如下:
class CXFClient { throws Exception,IllegalAccessException,InvocationTargetException {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:9080/WS_CXF/webservice/sendServie?wsdl");
client.invoke("sendOA",255);">"aa");
}
}
原文链接:/webservice/832739.html