我尝试用所有不同的方法在谷歌上搜索几个小时。
这里是调用 ASP .Net C# 中的 Web 服务方法的 Java 代码
public DefaultTableModel SelectAllProjects ()
{
try{
DefaultTableModel DtM;
Collection c = (Collection)wws.selectAllProjects();
Iterator iter = c.iterator();
DtM = new DefaultTableModel();
DtM.addColumn("Project ID:");
DtM.addColumn("Project Name:");
DtM.addColumn("Project Description:");
Vector vec = new Vector(c.size());
while(iter.hasNext()){
Project p = new Project();
p.getPId();
p.getPName();
p.getPDescript();
vec.add(p);
DtM.addRow(vec);
}
return DtM;
}
catch(Exception e)
{
System.out.println(e);
return null;
}
}
这是网络服务方法......
[WebMethod]//Ska vara collection
public List<Project> SelectAllProjects()
{
Controller contr = new Controller();
List<Project> project = contr.SelectAllProjects();
return project;
}
我知道该方法有效,因为用 C# 编写的 Windows 窗体应用程序可以成功调用它。
我也知道 Java 和 Web 服务之间的联系,因为我可以调用其他方法。
我的 Catch(Exception e) 返回以下消息:
java.lang.ClassCastException: javaapp.ArrayOfProject cannot be cast to java.util.Collection
感谢您的回答,找不到任何接近的东西。
Ps 试过Object[] obj = (Object[])wws.selectAllProjects();
了Project[] proj = (Project [])wws.selectAllProjects();
请求自动生成的 ArrayOfProject.java 类
package javaapp;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import java.util.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfProject", propOrder = { "project" })
public class ArrayOfProject {
@XmlElement(name = "Project", nillable = true)
protected List<Project> project;
public List<Project> getProject() {
if (project == null) {
project = new ArrayList<Project>();
}
return this.project;
}
}
代码来自我的视图类..(我按下的按钮)
private void btnAllProjects_actionPerformed(ActionEvent e) {
try{
Controller control = new Controller();
DefaultTableModel DtM;
DtM = control.SelectAllProjects();
JTable selectProjectsTable = new JTable (DtM);
}
catch (Exception ex)
{
System.out.println(ex);
}
}
我最新的例外列表:
C:\Oracle\Middleware\jdk160_24\bin\javaw.exe -client -classpath "C:\Users\MS\Desktop\Web Services\Java Uppgift 2\.adf;C:\Users\MS\Desktop\Web Services\Java Uppgift 2\JavaApp\classes;C:\Oracle\Middleware\wlserver_10.3\server\lib\weblogic.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.jrf_11.1.1\jrf.jar;C:\Oracle\Middleware\modules\com.oracle.toplink_1.0.0.0_11-1-1-5-0.jar;C:\Oracle\Middleware\modules\org.eclipse.persistence_1.1.0.0_2-1.jar;C:\Oracle\Middleware\modules\com.bea.core.antlr.runtime_2.7.7.jar;C:\Oracle\Middleware\modules\javax.persistence_1.0.0.0_2-0-0.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xmlparserv2.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.xdk_11.1.0\xml.jar;C:\Oracle\Middleware\oracle_common\modules\oracle.nlsrtl_11.1.0\orai18n-mapping.jar" -Djavax.net.ssl.trustStore=C:\Users\MS\AppData\Local\Temp\trustStore7859653733656575754.jks javaapp.Main
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.Vector.ensureCapacityHelper(Vector.java:226)
at java.util.Vector.insertElementAt(Vector.java:554)
at javax.swing.table.DefaultTableModel.insertRow(DefaultTableModel.java:357)
at javax.swing.table.DefaultTableModel.addRow(DefaultTableModel.java:333)
at javaapp.Controller.SelectAllProjects(Controller.java:56)
at javaapp.View.btnAllProjects_actionPerformed(View.java:103)
at javaapp.View.access$200(View.java:24)
at javaapp.View$3.actionPerformed(View.java:68)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6289)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6054)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4652)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4482)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:603)
at java.awt.EventQueue$1.run(EventQueue.java:601)