java使用axis调用.net发布的webservice接口返回对象类型

本人在java中axis-1.4 调用 .net发布的webService接口
有问题欢迎各路大神讨论 !!!

1.1 基本类型
1.2 对象类型
1.3复杂对象类型(对象类中嵌套对象类)

返回基本类型


		Service service = new Service();
		String url = "http://192.168.129.21:8010/Service.asmx";
		//在浏览器中打开url,可以找到SOAPAction: "http://www.chinsoft.com.cn/SendMQ"
		String namespace = "http://tempuri.org/";
		String actionUri = "IsABookedRoom"; //Action路径
		String op = "IsABookedRoom"; //要调用的方法名
		Call call = (Call) service.createCall();
		call.setTargetEndpointAddress(new java.net.URL(url));
		call.setUseSOAPAction(true);
		call.setSOAPActionURI(namespace + actionUri); // action uri
		call.setOperationName(new QName(namespace, op));// 设置要调用哪个方法
		// 设置参数名称,具体参照从浏览器中看到的
		call.addParameter(new QName(namespace, "roomID"), XMLType.XSD_STRING, ParameterMode.IN);
		call.addParameter(new QName(namespace, "startTime"), XMLType.XSD_STRING, ParameterMode.IN);
		call.addParameter(new QName(namespace, "endTime"), XMLType.XSD_STRING, ParameterMode.IN);

		call.setReturnType(XMLType.XSD_BOOLEAN);
		Object[] params = new Object[] {"3","2019-02-19 10:00:00","2019-02-19 10:30:00"};
		//如果不需要传参  Object[] params = new Object[] {}  
		Boolean boolean = (Boolean) call.invoke(params); //方法执行后的返回值
		ModelAndView mv = new ModelAndView("test"); //返回视图
        mv.addObject("boolean", boolean);
        return mv;



返回对象类 (例MeetingRoom)

		Service service = new Service();
		String url = "http://192.168.129.21:8010/Service.asmx";
		//在浏览器中打开url,可以找到SOAPAction: "http://www.chinsoft.com.cn/SendMQ"
		String namespace = "http://tempuri.org/";
		String actionUri = "GetMeetingRoomByID"; //Action路径
		String op = "GetMeetingRoomByID"; //要调用的方法名
		Call call = (Call) service.createCall();
		//将MeetingRoom进行序列化  当然 实体类也要implements Serializable
		call.registerTypeMapping(MeetingRoom.class, new QName(namespace, actionUri),
        		new BeanSerializerFactory(MeetingRoom.class, new QName(namespace, actionUri)),
                new BeanDeserializerFactory(MeetingRoom.class, new QName(namespace, actionUri))); 
		call.setTargetEndpointAddress(new java.net.URL(url));
		call.setUseSOAPAction(true);
		call.setSOAPActionURI(namespace + actionUri); // action uri
		call.setOperationName(new QName(namespace, op));// 设置要调用哪个方法
		// 设置参数名称,具体参照从浏览器中看到的
		call.addParameter(new QName(namespace, "roomID"), XMLType.SOAP_STRING, ParameterMode.IN);
		call.setReturnClass(MeetingRoom.class); // 要返回的数据类型
		Object[] params = new Object[] {"3"};
		MeetingRoom meetingRoom = (MeetingRoom) call.invoke(params);
		//System.out.println(meetingRoom );
		ModelAndView mv = new ModelAndView("home");
        mv.addObject("meetingRoom ", meetingRoom );
        return mv;

返回嵌套对象(返回A类,A类中包含B类和C类 下边会贴出wsdl 和实体类 )

		Service service = new Service();
		String url = "http://192.168.129.21:8010/Service.asmx";
		//在浏览器中打开url,可以找到SOAPAction: "http://www.chinsoft.com.cn/SendMQ"
		String namespace = "http://tempuri.org/";
		String actionUri = "GetRoomBookedDayInfo"; //Action路径
		String op = "GetRoomBookedDayInfo"; //要调用的方法名
		Call call = (Call) service.createCall();
		//也是序列化  很烦  ------start
		TypeMappingRegistry registry =  (TypeMappingRegistry) service.getTypeMappingRegistry();
		TypeMapping mapping = (TypeMapping) registry.createTypeMapping();
         
	    mapping.register(BookedRoomInfo.class,new QName(namespace, actionUri),
	    		new BeanSerializerFactory(BookedRoomInfo.class, new QName(namespace, actionUri)),
	    		new BeanDeserializerFactory(BookedRoomInfo.class, new QName(namespace, actionUri)));
     
	    mapping.register(MeetingRoom.class,new QName(namespace, "MeetingRoom"),
			    new BeanSerializerFactory(MeetingRoom.class, new QName(namespace, "MeetingRoom")),
			    new BeanDeserializerFactory(MeetingRoom.class, new QName(namespace, "MeetingRoom")));
     
	    mapping.register(UserInfo.class,new QName(namespace, "UserInfo"),
	    		new BeanSerializerFactory(UserInfo.class, new QName(namespace, "UserInfo")),
	    		new BeanDeserializerFactory(UserInfo.class, new QName(namespace, "UserInfo")));
     
        registry.register("http://schemas.xmlsoap.org/soap/encoding/", mapping);
       //也是序列化  很烦  ------end
       
		call.setTargetEndpointAddress(new java.net.URL(url));
		call.setUseSOAPAction(true);
		call.setSOAPActionURI(namespace + actionUri); // action uri
		call.setOperationName(new QName(namespace, op));// 设置要调用哪个方法
		// 设置参数名称,具体参照从浏览器中看到的
		call.addParameter(new QName(namespace, "roomID"), XMLType.SOAP_STRING, ParameterMode.IN);
		call.addParameter(new QName(namespace, "bookedDay"), XMLType.SOAP_STRING, ParameterMode.IN);
		
		// 要返回的数据类型  wsdl中返回对象 对应 <type:ArrayOfBookedRoomInfo>
		//看到网上有人用call.setReturnClass(List.class); 但是本人使用报错 返回值类型不正确 所以试了一下数组
		call.setReturnClass(BookedRoomInfo[].class); 
		 
		Object[] params = new Object[] {"3","2019-02-19"};
		BookedRoomInfo[] bInfos = (BookedRoomInfo[]) call.invoke(params);
		ModelAndView mv = new ModelAndView("home");
		for (BookedRoomInfo bookedRoomInfo : bInfos) {
			System.out.println(bookedRoomInfo);
		}
        mv.addObject("bInfos", bInfos);
        return mv;

wsdl部分信息

wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="HelloWorld">
<s:complexType/>
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="InsertRoomBooked">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="bookingRoom" type="tns:BookedRoomInfo"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="BookedRoomInfo">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="meetingRoom" type="tns:MeetingRoom"/>
<s:element minOccurs="0" maxOccurs="1" name="user" type="tns:UserInfo"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedDate" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="meetingContent" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedTimeStart" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedTimeEnd" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="valid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="createTime" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="updateTime" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="userTel" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="meetingType" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedHourStart" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedHourEnd" type="s:string"/>
</s:sequence>
</s:complexType>
<s:complexType name="MeetingRoom">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="roomID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomType" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomTypeName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="positionID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="positionName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="orderID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomDesc" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomTel" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomStatus" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="roomCount" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="supportVideo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="ImageInfo" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="managerNo" type="s:string"/>
</s:sequence>
</s:complexType>
<s:complexType name="UserInfo">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="workCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="celler" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PinYin" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="userTel" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="userMail" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="userRole" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="InsertRoomBookedResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="InsertRoomBookedResult" type="s:boolean"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="IsABookedRoom">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="roomID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="startTime" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="endTime" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="IsABookedRoomResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="IsABookedRoomResult" type="s:boolean"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetRoomBookedDayInfo">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="roomID" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="bookedDay" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetRoomBookedDayInfoResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetRoomBookedDayInfoResult" type="tns:ArrayOfBookedRoomInfo"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfBookedRoomInfo">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="BookedRoomInfo" nillable="true" type="tns:BookedRoomInfo"/>
</s:sequence>
</s:complexType>
<s:element name="GetMeetingRoomByID">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="roomID" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetMeetingRoomByIDResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetMeetingRoomByIDResult" type="tns:MeetingRoom"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>

实体类

package com.web.service.pojo;

import java.io.Serializable;

public class BookedRoomInfo implements Serializable{
	
	private MeetingRoom meetingRoom; 
	private UserInfo user; 
	private String bookedID; 
	private String bookedDate; 
	private String meetingContent; 
	private String bookedTimeStart; 
	private String bookedTimeEnd; 
	private String valid; 
	private String createTime; 
	private String updateTime; 
	private String userTel; 
	private String meetingType; 
	private String bookedHourStart; 
	private String bookedHourEnd;
	public get/set{
	 	......
	}
	@Override
	public String toString() {
		.....
	}
	public BookedRoomInfo(MeetingRoom meetingRoom, UserInfo user, String bookedID, String bookedDate,
			String meetingContent, String bookedTimeStart, String bookedTimeEnd, String valid, String createTime,
			String updateTime, String userTel, String meetingType, String bookedHourStart, String bookedHourEnd) {
		super();
		this.meetingRoom = meetingRoom;
		this.user = user;
		this.bookedID = bookedID;
		......
	}
	public BookedRoomInfo() {
		super();
	} 
}

package com.web.service.pojo;

import java.io.Serializable;

public class MeetingRoom implements Serializable{
	 //private static final long serialVersionUID = -971720598087640397L; 
	private String roomID;
	private String roomName;
	private String roomType;
	private String roomTypeName;
	private String positionID;
	private String positionName;
	private String orderID;
	private String roomDesc;
	private String roomTel;
	private String roomStatus;
	private String roomCount;
	private String supportVideo;
	private String ImageInfo;
	private String managerNo;
	
	public  get/set(){
		......
	}
	public MeetingRoom() {
		super();
	}
	@Override
	public String toString() {
		......
	}
	public MeetingRoom(String roomID, String roomName, String roomType, String roomTypeName, String positionID,
			String positionName, String orderID, String roomDesc, String roomTel, String roomStatus, String roomCount,
			String supportVideo, String imageInfo, String managerNo) {
		super();
		this.roomID = roomID;
		......
	}
	
			
	
}

package com.web.service.pojo;

import java.io.Serializable;

public class UserInfo implements Serializable{
	
	private String userID;
	private String workCode;
	private String celler;
	private String PinYin;
	private String userName;
	private String userTel;
	private String userMail;
	private String userRole;
	
	public get/set(){
		......
	}
	@Override
	public String toString() {
		......
	}
	public UserInfo(String userID, String workCode, String celler, String pinYin, String userName, String userTel,
			String userMail, String userRole) {
		super();
		this.userID = userID;
		......
	}
	public UserInfo() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	
}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 1

打赏作者

野生猿

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值