WebService以前使用都是传递简单的字符串之类的参数,后面有项目需传递复杂对象类型参数,于是研究学习了下。
使用jar包:axis-1.4.jar
接口类型代码片段:
AccountRequest对象片段:
伦理片 http://www.dotdy .com/
AccountResponse对象片段:
SearchAccountsResponse对象片段:
AccountInfo对象片段:
使用 deploy.wsdd 生成service-config.wsdd:(deploy.wsdd 放于WEB-INF下)
我自己弄个批处理(复制到一个txt文件,保存为.bat文件即可运行):
deploy.wsdd:
要注意那2个arrayMapping的设置。
服务发布成功后,访问你的服务,把显示的网页保存为.wsdl文件。
根据这个文件,就可以生成相应的代码。
这个功能我也弄了个批处理:
执行上面的批处理,会在设置的Output_Path文件夹下面生成相关的代码,以及deploy.wsdd,undeploy.wsdd文件,根据这些文件,就可以调用前面发布的服务了。
影音先锋电影 http://www.iskdy .com/
调用测试:
1、客户端调用。
这个就不搞了,有了客户端代码就很简单了。
2、Call方式调用,这个要说下。
上述都是代码片段,仅供参考。
使用jar包:axis-1.4.jar
接口类型代码片段:
- //暂挂一个有效账号的服务
- public AccountResponse suspendAccount(AccountRequest accountInfo);
- //检查一个有效账号的密码是否正确的服务
- public AccountResponse validatePassword(AccountRequest accountInfo);
- 测试与Web Service的通讯是否正常的服务
- public AccountResponse testConnection(AccountRequest accountInfo);
- //修改一个有效账号可修改属性的服务
- public AccountResponse modifyAccount(AccountRequest accountInfo);
- //恢复一个已暂挂账号的服务
- public AccountResponse restoreAccount(AccountRequest accountInfo);
- //查询并返回全部或符合查询条件的账号集合的服务
- public SearchAccountsResponse searchAccounts(AccountRequest accountInfo);
- //创建一个新账号的服务
- public AccountResponse addAccount(AccountRequest accountInfo);
- //删除一个账号的服务
- public AccountResponse deleteAccount(AccountRequest accountInfo);
- //修改一个有效账号密码的服务
- public AccountResponse changePassword(AccountRequest accountInfo);
AccountRequest对象片段:
public class AccountRequest implements Serializable{
/**
* 请求唯一标识 字符串,每次请求唯一
*/
private String requestID;
* 账号信息对象 用户数据对象
private AccountInfo accountInfo;
}
伦理片 http://www.dotdy .com/
AccountResponse对象片段:
class AccountResponse * 请求唯一标识 字符串,每次响应唯一,与请求时的ID保持一致
* 处理结果标识 true:处理成功 false:处理失败
private Boolean returnFlag;
* 返回结果编号 由应用自行定义;
当returnFlag为true时,returnCode为0;
当returnFlag为false时,returnCode为错误编码
private String returnCode;
* 返回结果信息 由应用自行定义,可放入提示、警告或错误信息描述
private String returnMessage;
}
SearchAccountsResponse对象片段:
class SearchAccountsResponse {
private AccountInfo[] accountInfoList;
private Integer accountInfoSize;
}
AccountInfo对象片段:
class AccountInfo * 用户应用账号 应用账号ID
private String accountID;
* 人员中文姓名
private String cn;
* 应用登录密码
private String userPassword;
* 兼职部门ID
private String[] workOrg;
* 兼职部门名称
private String[] workOrgName;
}
使用 deploy.wsdd 生成service-config.wsdd:(deploy.wsdd 放于WEB-INF下)
我自己弄个批处理(复制到一个txt文件,保存为.bat文件即可运行):
D:
cd D:\workspaceEclipse\AxisTest\WebContent\WEB-INF
java org.apache.axis.client.AdminClient -lhttp://127.0.0.1:8080/AxisTest/services/AdminService deploy.wsdd
@echo 已经成功生成,代码在D:\workspaceEclipse\AxisTest\WebContent\WEB-INF目录下
@echo -----------------------------------------
@pause
deploy.wsdd:
- <?xml version="1.0" encoding="UTF-8"?>
- <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
- service name="exoaUmService" provider="java:RPC" style="wrapped" use="literal" parameter name="wsdlTargetNamespace" value="http://cn.com"/>
- parameter name="wsdlServiceElement" value="exUmService"parameter name="schemaQualified" value="http://cn.com"parameter name="wsdlServicePort" value="exUmServiceHttpPort"parameter name="className" value="com.axis.test.ExUmService"parameter name="wsdlPortType" value="exUmServicePortType"parameter name="typeMappingVersion" value="1.2"operation name="suspendAccount" qname="operNS:suspendAccount" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" parameter qname="pns:accountInfo" xmlns:pns="http://cn.com" type="tns:AccountRequest" xmlns:tns="http://cn.com"</operationoperation name="validatePassword" qname="operNS:validatePassword" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="testConnection" qname="operNS:testConnection" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="modifyAccount" qname="operNS:modifyAccount" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="restoreAccount" qname="operNS:restoreAccount" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="searchAccounts" qname="operNS:searchAccounts" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:SearchAccountsResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="addAccount" qname="operNS:addAccount" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="deleteAccount" qname="operNS:deleteAccount" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" operation name="changePassword" qname="operNS:changePassword" xmlns:operNS="http://cn.com" returnQName="retNS:out" xmlns:retNS="http://cn.com" returnType="rtns:AccountResponse" xmlns:rtns="http://cn.com" soapAction="" parameter name="allowedMethods" value="*"typeMapping
- xmlns:ns="http://cn.com"
- qname="ns:SearchAccountsResponse"
- type="java:com.axis.test.SearchAccountsResponse"
- serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
- deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
- encodingStyle=""
- qname="ns:AccountInfo"
- type="java:com.axis.test.AccountInfo"
- arrayMapping
- qname="ns:ArrayOfAccountInfo"
- type="java:com.axis.test.AccountInfo[]"
- innerType="cmp-ns:AccountInfo" xmlns:cmp-ns="http://cn.com"
- qname="ns:AccountResponse"
- type="java:com.axis.test.AccountResponse"
- qname="ns:AccountRequest"
- type="java:com.axis.test.AccountRequest"
- qname="ns:arrayofstring"
- type="java:java.lang.String[]"
- innerType="cmp-ns:string" xmlns:cmp-ns="http://www.w3.org/2001/XMLSchema"
- servicedeployment>
要注意那2个arrayMapping的设置。
服务发布成功后,访问你的服务,把显示的网页保存为.wsdl文件。
根据这个文件,就可以生成相应的代码。
这个功能我也弄了个批处理:
set Axis_Lib=F:\axis\axis-1_4\lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=F:\axis\service
set Package=com.test.webservice
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o %Output_Path% -p %Package% -s F:\axis\exUmService.wsdl
@echo 客户端代码已经成功生成,代码在F:\axis\service目录下
@pause
执行上面的批处理,会在设置的Output_Path文件夹下面生成相关的代码,以及deploy.wsdd,undeploy.wsdd文件,根据这些文件,就可以调用前面发布的服务了。
影音先锋电影 http://www.iskdy .com/
调用测试:
1、客户端调用。
这个就不搞了,有了客户端代码就很简单了。
2、Call方式调用,这个要说下。
void test(String methodName,AccountRequest accountInfo){
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(targetEendPoint));
QName qn = new QName("http://cn.com", "AccountInfo" );
call.registerTypeMapping(AccountInfo.class,qn,
new BeanSerializerFactory(AccountInfo.new BeanDeserializerFactory(AccountInfo. QName qn2 = "AccountResponse" );
call.registerTypeMapping(AccountResponse.new BeanSerializerFactory(AccountResponse.new BeanDeserializerFactory(AccountResponse. QName qn3 = "AccountRequest" );
call.registerTypeMapping(AccountRequest.new BeanSerializerFactory(AccountRequest.new BeanDeserializerFactory(AccountRequest. QName qn4 = "SearchAccountsResponse" );
call.registerTypeMapping(SearchAccountsResponse.new BeanSerializerFactory(SearchAccountsResponse.new BeanDeserializerFactory(SearchAccountsResponse. QName qn5 = "ArrayOfAccountInfo" );
call.registerTypeMapping(AccountInfo[].new ArraySerializerFactory(qn, null),85); font-weight:bold">new ArrayDeserializerFactory());//留意此处
call.setoperationName( call.addParameter( "arg1", qn3, ParameterMode.IN );
if("searchAccounts".equals(methodName)){
call.setReturnClass(SearchAccountsResponse.class);
SearchAccountsResponse result = (SearchAccountsResponse) call.invoke( new Object[] {accountInfo} );
AccountInfo[] att=result.getAccountInfoList();
}else{
call.setReturnClass(AccountResponse. AccountResponse result = (AccountResponse) call.invoke( }
}
上述都是代码片段,仅供参考。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。