How to reuse a server class in a JAX-WS client?

I have a server side class: ForumEntry, and I have a web service that returns a ForumEntry list:

@WebService(name="ForumGeneral",serviceName="ForumGeneralService") public class ForumGeneralService { @WebMethod public List<ForumEntry> getLatestTopics(String keyword,int count){ ... } } 

When using wsimport to generate the webservice client, it ends fine, but the new ForumEntry type is based on a web service. This makes sense because the nature of the web service is that the client and server are separate from each other.

But what if I want to reuse the ForumEntry backend and avoid creating the created dummy class on the client side?

I found the post: http://jamablog.blogspot.com/2007/08/how-to-make-jax-ws-client-reuse_22.html .

Follow the idea, I added jaxb annotations to the back end of the ForumEntry class:

 @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "forumEntry", propOrder = { "forumId", "forumName", }) public class ForumEntry 

then used the circuit to generate the episode file, and then passed it to wsimport using the -b option. But I had a problem, because the created episode file contains entries for "forumEntry":

 [ERROR] SCD "~forumEntry" didnt match any schema component 

I assume this means that "forumEntry is not displayed in WSDL, which is correct:

 <message name="getLatestTopics"> <part name="parameters" element="tns:getLatestTopics"></part> </message> <message name="getLatestTopicsResponse"> <part name="parameters" element="tns:getLatestTopicsResponse"></part> </message> 

So how do all the parts fit together to reuse a server-side class?

+6
source share
1 answer

You must add the ForumEntry class to the schema so that the client can generate it and use this generated class on your server side. Or add a new class to your schema that contains similar data for ForumEntry, and create a server to create these objects when responding from ForumEntry objects and return these created objects.

0
source

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


All Articles