4

请问您能帮忙解决以下问题吗?

当生成 WS 客户端代码(使用 wsimport ant 任务)时,所有类都会自动生成在与 Web 服务相同的包(例如 helloservice.endpoint)中,例如,如果我的 Web 服务有方法

公共节点 getNode();

因此生成了类 helloservice.endpoint.Node。不过,我有自己的 helloservice.Node 类,我想在 Web 服务中使用它。

我定义了 bind.xml 文件:


<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" >
    <bindings node="wsdl:definitions/wsdl:portType[@name='Node']">
        <class name="helloservice.Node"/>
    </bindings>
</bindings>

and pass it to wsimport task as binding parameter, but get the error :

 [wsimport] [ERROR] XPath evaluation of "wsdl:definitions/wsdl:portType[@name='Node']" results in empty target node
 [wsimport]   line 2 of file:/C:/work/projects/svn.ct/trunk/jwstutorial20/examples/jaxws/simpleclient/bind.xml

请问有人可以推荐这里有什么问题吗?我可以以这种方式在生成的 Web 服务类中使用我自己的类,还是我需要更复杂的东西?

提前致谢。

4

1 回答 1

5

要从 wsdl 生成类,请在 ant 中使用:


<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<wsimport keep="true" sourcedestdir="..." wsdl="..." wsdllocation="..." xnocompile="true" />

不要在 wsimport ant 任务上使用 'package' 属性,因此所有类都在其正确的包中创建。

一般来说,要自定义包,即将生成的包名 abc 更改为名称 xyz 添加元素到 wsimport 任务并定义 binding.jxb 文件如下。


<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="schema-for-a.b.c.xsd" node="/xs:schema">
        <jxb:schemaBindings>
            <jxb:package name="x.y.z" />
        </jxb:schemaBindings>
    </jxb:bindings>
</jxb:bindings>

其中 schema-for-abcxsd 是由 wsgen 任务生成的模式(它使用合适的方案创建 wsdl)。

有关 JAXB 自定义的更多详细信息:http: //docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JavaWSTutorial.pdf,“自定义 JAXB 绑定”部分

于 2010-06-22T14:50:11.197 回答