= \ String nameSpaceUri
= \ // 创建调用对象
Service service = new Service(); Call call = null;
call = (Call) service.createCall(); // 调用 getMessage
System.out.println(\
call.setOperationName(new QName(nameSpaceUri, \ call.setTargetEndpointAddress(new java.net.URL(wsdlUrl)); String ret = (String) call.invoke(new Object[] { \ System.out.println(\ }
catch (Exception e) {
e.printStackTrace(); } } } 本
文
来
自
CSDN
博
客
,
转
载
请
标
明
出
处
:
http://blog.csdn.net/thinker28754/archive/2008/04/23/2318236.aspx
在spring中利用axis工具配置webservice成功案例
第一步:确认你用到的spring bean存在并且有效 比如 inviteService 第二步:创建要发布的服务方法 /** * */
package com.chinamobile.survey.webservice;
import java.util.List;
import org.springframework.remoting.jaxrpc.ServletEndpointSupport; import com.chinamobile.survey.entity.vo.ExamPlanContainer; import com.chinamobile.survey.invite.business.IInviteService; /**
* @author jianqiang.jiang * */
public class InviteEndPoint extends ServletEndpointSupport implements IInviteService {
// 将真实的业务bean包装成WebService private IInviteService inviteService;
// 该方法由Spring调用,将目标业务bean注入。 protected void onInit() {
this.inviteService = (IInviteService) getWebApplicationContext() .getBean(\ }
// 将业务bean的业务方法暴露成WebService
public int getAllowAnswerExamPlanCount(long userId) throws Exception { return inviteService.getAllowAnswerExamPlanCount(userId); }
public ExamPlanContainer getAllowAnswerExamPlanContainer(long userId, long offset, long maxRow) throws Exception {
return inviteService.getAllowAnswerExamPlanContainer(userId, offset, maxRow); }
}
注意里面的 ServletEndpointSupport 和对bean的引用 第三步.编辑两个文件 1.web.xml中 增加
org.apache.axis.transport.http.AxisServlet
2.生成server-config.wsdd,放在WEB-INF下
type=\ value=\ value=\/> languageSpecificType=\ainer\
注意其中的 返回类型注册, 第四步.
生成客户端测试代码:
package com.chinamobile.survey.webservice; import java.util.Iterator; import java.util.List;
import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.BeanDeserializerFactory; import org.apache.axis.encoding.ser.BeanSerializerFactory; import com.chinamobile.survey.entity.vo.ExamPlanContainer; import com.chinamobile.survey.entity.vo.WsExamPlan; public class ArchiveClient {
public static void main(String args[]) throws Exception { try {
String endpoint = \ Service service = new Service(); Call call = (Call) service.createCall();
QName searchresultqn = new QName(\ \
Class searchresultcls = ExamPlanContainer.class; call
.registerTypeMapping(searchresultcls, searchresultqn, new BeanSerializerFactory(searchresultcls, searchresultqn),
new BeanDeserializerFactory(searchresultcls, searchresultqn));
QName wsExamPlanQN = new QName(\ Class wsepcls = WsExamPlan.class;
call.registerTypeMapping(wsepcls, wsExamPlanQN,