如何使用WSDL2Java生成的文件?

我使用在axis2-1.5中找到的wsdl2java生成了.java文件。 现在它生成了这个文件夹结构中的文件:src / net / mycompany / www / services /

services文件夹中的文件是:SessionIntegrationStub和SessionIntegrationCallbackHandler。

我现在想要使用web服务。 我将net文件夹添加到CLASSPATH环境变量中。 我的java文件现在使用以下方法导入webservice:

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

任何想法?

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

 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() 

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

这应该可以说是import net.mycompany.www.services.*; 。 你错过了星号。

这里的问题是你的包结构。 您的test.java位于不同的包中,然后是您生成的源。

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

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