我使用 axis2-1.5 中的 wsdl2java 生成了 .java 文件。现在它生成了这个文件夹结构中的文件:src/net/mycompany/www/services/
services文件夹中的文件有:SessionIntegrationStub和SessionIntegrationCallbackHandler。
我现在想使用网络服务。我将 net 文件夹添加到 CLASSPATH 环境变量中。我的 java 文件现在使用以下方式导入 web 服务:
import net.mycompany.www.services;
public class test
{
public static void main(String[] args)
{
SessionIntegrationStub stub = new SessionIntegrationStub();
System.out.println(stub.getSessionIntegration("test"));
}
}
现在,当我尝试使用以下方法编译它时:
javac 测试.java
我得到:包 net.mycompany.www 不存在。
有什么想法吗?
最佳答案
如前所述,您需要导入生成的 stub 类,而不是包
import net.mycompany.www.services.SessionIntegrationStub;
然后您需要填充您的 XML 请求对象。我不知道您的 WSDL 是什么样子,但是例如
SessionIntegrationStub.SessionRequest req = new SessionIntegrationStub.SessionRequest()
req.setParamOne(1)
req.setParamTwo(2)
最后调用网络服务
SessionIntegrationStub.SessionResponse resp = stub.operationOne(req)
println resp.getAnswer()
注意:上面的 setter 和 getter 对应于您的架构中声明的元素。 SessionRequest 和 SessionResponse 类将对应于您的架构中声明的复杂类型。
关于java - 如何使用 WSDL2Java 生成文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2299242/