You must use custom classes instead of the generated ones (by wsimport) in web services

Could you help with the following problem?

When generating WS client code (with the wsimport ant task), all classes are automatically generated in one package (for example, helloservice.endpoint) as a web service, for example. if my web service has a method

public Node getNode ();

therefore, the helloservice.endpoint.Node class is generated. However, I have my own helloservice.Node class that I want to use in a web service.

I defined the 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 someone please recommend what is wrong here? Can I use my own classes in the generated web service classes this way, or do I need something more complex?

Thanks in advance.

+4
source share
1 answer

To create classes from wsdl, use in ant:

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

Do not use the "package" attribute in the wsimport ant task, so all classes are created in their correct packages.

In general, to configure the package, i.e. generate the name of the generated abc package to name xyz add the item to the wsimport task and define the 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-abcxsd" node="/xs:schema"> <jxb:schemaBindings> <jxb:package name="xyz" /> </jxb:schemaBindings> </jxb:bindings> </jxb:bindings> 

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

Learn more about setting up JAXB: http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JavaWSTutorial.pdf , section "Setting up JAXB bindings"

+5
source

Source: https://habr.com/ru/post/1311646/


All Articles