简体   繁体   English

需要使用自定义类而不是在Web服务中生成(通过wsimport)

[英]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 当生成WS客户端代码(使用wsimport ant任务)时,所有类都在与Web服务相同的包(例如helloservice.endpoint)中自动生成,例如,如果我的Web服务具有方法

public Node getNode(); public Node getNode();

so class helloservice.endpoint.Node is generated. 所以生成了类helloservice.endpoint.Node。 Nevertheless, I have my own helloservice.Node class that I want to use in web-service. 不过,我有自己的helloservice.Node类,我想在web服务中使用。

I defined bind.xml file : 我定义了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

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? 我可以用这种方式在生成的Web服务类中使用我自己的类,还是我需要更复杂的smth?

Thanks in advance. 提前致谢。

To generate classes from wsdl, use in ant : 要从wsdl生成类,请在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. 不要在wsimport ant任务上使用'package'属性,因此所有类都在正确的包中创建。

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. 通常,要自定义包,即更改生成的包名称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>

where schema-for-abcxsd is the schema generated by wsgen task (that creates wsdl with suitable schemes). schema-for-abcxsd是由wsgen任务生成的模式(使用合适的方案创建wsdl)。

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" 有关JAXB定制的更多详细信息: http//docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JavaWSTutorial.pdf ,“自定义JAXB绑定”部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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