2

我使用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 test.java

我得到:包 net.mycompany.www 不存在。

任何想法?

4

3 回答 3

2

如前所述,您需要导入生成的存根类,而不是包

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 类将对应于您的架构中声明的复杂类型。

于 2010-04-02T08:39:53.997 回答
0

想必应该这样说import net.mycompany.www.services.*;。你错过了星号。

于 2010-02-19T20:31:23.067 回答
0

这里的问题是你的包结构。您的 test.java 与您生成的源代码不同。

您需要将当前文件保留在相同的包结构中或在 javac 中提供生成源的完整路径,例如

javac src/net/mycompany/www/services/ .java src/net/mycompany/services/ .java

于 2010-04-03T18:35:08.440 回答