xfire 客戶端呼叫webservice的問題

jvcoffee發表於2008-03-19
介面:
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修改過]

相關文章