下面是我的测试程序。我想通过WSIF调用网上的一个查询飞机时刻表的服务。WSDL链接为http://www.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl,大家可以打开看看,里面有个复杂数据类型,我调用的时候出现了“服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。”的错误。请大侠们帮我看看。
package org.ufonaughty;import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFPort;
import org.apache.wsif.WSIFService;
import org.apache.wsif.WSIFServiceFactory;
import org.ufonaughty.GetDomesticAirlinesTime;/**
 * @author ufonaughty
 * @date Dec 4, 2008
 * @time 10:33:44 PM
 */
public class WisfTest {
public static void main(String arg[]) throws ClassNotFoundException {
try {
String url = "http://www.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl";
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
// AuthenticatingProxyWSDLLocatorImpl awsli=new
// AuthenticatingProxyWSDLLocatorImpl(url,"gaolong1","19831001");
WSIFService service = factory.getService(url,
"http://WebXml.com.cn/",
"DomesticAirline",
"http://WebXml.com.cn/", "DomesticAirlineSoap");
service.mapType(
                new javax.xml.namespace.QName(
                 "http://WebXml.com.cn/",
                    "getDomesticAirlinesTime"),
              GetDomesticAirlinesTime.class);

// 其参数分别代表:WSDL地址参数,Service命名空间参数,WSDL文档中Service名称参数,WSDL文档中的portType命名空间参数,WSDL文档中的portType名称参数
WSIFPort port = service.getPort();
WSIFOperation operation = port.createOperation("getDomesticAirlinesTime",
"getDomesticAirlinesTimeSoapIn", "getDomesticAirlinesTimeSoapOut");
// 根据给定的操作名称参数operationName,输入元素名称inputName,输出元素名称outputName.
WSIFMessage input = operation.createInputMessage();
// String startCity = "长沙";
// String lastCity = "上海";
// String date = "";
// String userId = "";
Object inputParam = new GetDomesticAirlinesTime("长沙","上海","","");
input.setObjectPart("getDomesticAirlinesTime", inputParam);
// input.setObjectPart("lastCity", lastCity);
// input.setObjectPart("theDate", date);
// input.setObjectPart("userID", userId);

// 设置soap消息中part的表现内容
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
operation.executeRequestResponseOperation(input, output, fault);
String Info = (String) output.getObjectPart("Return"); // 执行请求和接受响应消息的方法,第一个组作为输入的input消息被发送到服务器端,第二个代表输入响应的信息会在执行后包含着返回的消息,第三个消息用来封装错误和状态消息。
System.out.println(Info);// 获得这个soap消息的表现内容
} catch (WSIFException we) {
we.printStackTrace();
}
} /**
 * @param getDomesticAirlinesTime
 * @return
 */
private static Object encodeBean(
GetDomesticAirlinesTime getDomesticAirlinesTime) {
// TODO Auto-generated method stub
ByteArrayOutputStream out = new ByteArrayOutputStream(); 
XMLEncoder encoder = new XMLEncoder(out); 
encoder.writeObject(getDomesticAirlinesTime); 
encoder.close();  return out;  }
}