xfire 客户端调用webservice的问题

08-03-19 jvcoffee
接口:
public interface IMainInterface {
public String logining(String userName,String passWord);
public byte[] downloadDisease(String userName,String passWord);
}
客户端: main方法
MainLogin mainLogin = new MainLogin();
String url = "http://localhost:8888/Data_ShareTransaction/services/maininterface";
String userName = "111";
String password = "111";
IMainInterface mainInterface = mainLogin.login(url, userName, password);

DownLoad downLoad = new DownLoad();
downLoad.download(userName, password, mainInterface);
//MainLogin
public class MainLogin {
private static XFireProxyFactory serviceFactory = new XFireProxyFactory();

public IMainInterface login(String url, String username, String password) {
// 建立接口模型
Service mainserverModel = new ObjectServiceFactory()
.create(IMainInterface.class);
String loginURL = url;
IMainInterface mainInterface = (IMainInterface) serviceFactory.create(
mainserverModel, loginURL);
Client client = ((XFireProxy) Proxy
.getInvocationHandler(mainInterface)).getClient();
client.addOutHandler(new DOMOutHandler());
return mainInterface;
}
}
//DownLoad
public class DownLoad {
public void download(String userName, String passWord, IMainInterface mainInterface) {
try {
byte[] bostsByte = mainInterface.downloadDisease(userName, passWord);

putFile(bostsByte,"E:\\testdownload_client\\test1.xml");
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}

}
services.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<!-- WebService Impl -->
<bean id="maininterfaceimpl"
class="com.viewhigh.dt.maininter.impl.MainInterfaceImpl" />

<bean id="baseWebService"
class="org.codehaus.xfire.spring.remoting.XFireExporter"
lazy-init="false" abstract="true">
<property name="serviceFactory" ref="xfire.serviceFactory" />
<property name="xfire" ref="xfire" />
</bean>

<bean parent="baseWebService">
<property name="serviceBean" ref="maininterfaceimpl" />
<property name="serviceClass"
value="com.viewhigh.dt.maininter.IMainInterface" />
<property name="name" value="maininterface" /><!-- Web Service名称 -->
<property name="inHandlers">
<list>
<ref bean="domInHandler" />
</list>
</property>
</bean>

<bean id="domInHandler"
class="org.codehaus.xfire.util.dom.DOMInHandler" />
</beans>

运行后抛出异常:
Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Fault: java.lang.NullPointerException
org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Fault: java.lang.NullPointerException
org.codehaus.xfire.fault.XFireFault: Fault: java.lang.NullPointerException
..
at $Proxy0.downloadDisease(Unknown Source)
at client.viewhigh.dt.DownLoad.download(DownLoad.java:22)
at client.viewhigh.dt.TestDownFile.main(TestDownFile.java:23)

为什么这里无法调用service呢?生成的客户端代理找不到真正的实现对象么?

[该贴被jvcoffee于2008-03-19 22:27修改过]

3
killer
2008-03-24 20:09
可能是你的服务没启动,通过IMainInterface mainInterface = mainLogin.login(url, userName, password);
获得的mainInterface 为空

猜你喜欢