如何使用WSDL2Java生成的文件?

2024-03-14

我使用 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 不存在。

任何想法?


正如已经建议的,您需要导入生成的存根类,而不是它的包

import net.mycompany.www.services.SessionIntegrationStub;

然后您需要填充 XML 请求对象。我不知道你的 WSDL 是什么样子,但例如

SessionIntegrationStub.SessionRequest req = new SessionIntegrationStub.SessionRequest()
req.setParamOne(1)
req.setParamTwo(2)

最后调用Web服务

SessionIntegrationStub.SessionResponse resp = stub.operationOne(req)

println resp.getAnswer()

Note:上面的 setter 和 getter 对应于模式中声明的元素。 SessionRequest 和 SessionResponse 类将对应于架构中声明的复杂类型。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用WSDL2Java生成的文件? 的相关文章

随机推荐