如何使用WSDL2Java生成的文件? [英] How to use WSDL2Java generated files?

查看:200
本文介绍了如何使用WSDL2Java生成的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I generated the .java files using wsdl2java found in axis2-1.5. Now it generated the files in this folder structure: src/net/mycompany/www/services/

services文件夹中的文件为:SessionIntegrationStub和SessionIntegrationCallbackHandler.

The files in the services folder are: SessionIntegrationStub and SessionIntegrationCallbackHandler.

我现在想使用Web服务.我将net文件夹添加到CLASSPATH环境变量中.我的Java文件现在使用以下命令导入Web服务:

I would like to consume the webservice now. I added the net folder to the CLASSPATH environment variable. My java file now imports the webservice using:

import net.mycompany.www.services;

public class test 
{ 
  public static void main(String[] args) 
  {
    SessionIntegrationStub stub = new SessionIntegrationStub();
    System.out.println(stub.getSessionIntegration("test"));
  } 
} 

现在,当我尝试使用以下命令进行编译时:

Now when I try to compile this using:

javac test.java

javac test.java

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

I get: package net.mycompany.www does not exist.

有什么主意吗?

推荐答案

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

As already suggested you need to import the generated stub class, not it's package

import net.mycompany.www.services.SessionIntegrationStub;

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

You then need to populate your XML request objects. I don't know what your WSDL looks like but for example

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类将与模式中声明的复杂类型相对应.

Note: The setters and getters above correspond to elements declared in your schema. The SessionRequest and SessionResponse classes would correspond to complex types declared in your schema.

这篇关于如何使用WSDL2Java生成的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆