編輯:用戶已經解決了他自己的問題。 @KMuir即使您找到解決方案,也可以發佈解決方案。
EmployeeService類的類接口是什麼?你確定它實現了遠程標記界面嗎?
public interface TunnelingMessageBox extends Remote {
public void pushMessage(Message message) throws RemoteException;
//..more interface methods
}
public class TunnelingMessageBoxImpl implements TunnelingMessageBox {
public void pushMessage(Message message) throws RemoteException {
// does the magic
}
}
public class MyService {
private Registry registry;
private int port;
public void createRegistry(int port) throws RemoteException {
Registry reg;
try {
reg = LocateRegistry.createRegistry(port);
} catch (ExportException ex) {
// get existing registry instance.
reg = LocateRegistry.getRegistry(port);
}
this.port=port;
registry = reg;
}
public vooid closeRegistry() {
try {
Remote obj = (Remote)registry.lookup("box1");
UnicastRemoteObject.unexportObject(obj, true);
registry.unbind("box1");
} catch(Exception ex) { ex.printStacktrace(); }
registry=null;
}
public void registerServices() throws RemoteException {
TunnelingMessageBoxImpl mbox = new TunnelingMessageBoxImpl();
UnicastRemoteObject.exportObject(mbox, port);
registry.rebind("box1", mbox);
}
}
我想出了這個問題。 – KMuir
否。下面的*錯誤信息*是*打印*,這是*而不是*程序的執行。 – EJP