简体   繁体   中英

need to use custom classes instead of generated (by wsimport) in web-services

Could you, please, help with the following issue?

When generate WS client code (with wsimport ant task), all classes are generated automatically in the same package (eg helloservice.endpoint) as web service, eg if my web-service has method

public Node getNode();

so class helloservice.endpoint.Node is generated. Nevertheless, I have my own helloservice.Node class that I want to use in web-service.

I defined bind.xml file :


<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

Could anybody, please, recommend what is wrong here? Can I use my own classes in generated web-service classes in such way, or I need smth more complicated?

Thanks in advance.

To generate classes from wsdl, use in ant :


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

Don't use 'package' attribute on wsimport ant task, so all classes are created in their correct packages.

In general, to customize package, ie change generated package name abc to name xyz add element to wsimport task and define binding.jxb file as follows.


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

where schema-for-abcxsd is the schema generated by wsgen task (that creates wsdl with suitable schemes).

More detailed about JAXB customization : http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JavaWSTutorial.pdf , section "Customizing JAXB Bindings"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM