How to reuse server side class in JAX-WS client?
I have a class on server side: ForumEntry, and I have a web service which returns a list of ForumEntry:
@WebService(name="ForumGeneral",serviceName="ForumGeneralService")
public class ForumGeneralService {
@WebMethod
public List<ForumEntry> getLatestTopics(String keyword,int count){
...
}
}
When using wsimport to generate webservice client, it finishes fine, but a new ForumEntry type's created based on the web service. That makes sense, as a nature of web service is that client and server sides are decoupled.
But what if I want to reuse the server side ForumEntry and avoid a client side dummy class being created?
I found a post: http://jamablog.blogspot.com/2007/08/how-to-make-jax-ws-client-reuse_22.html.
Follow the idea, I added jaxb annotations to my server side ForumEntry class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "forumEntry", propOrder = {
"forumId",
"forumName",
})
public class ForumEntry
then used schemagen to generate the episode file, then passing it to wsimport using -b parameter. But I got problem as the generated episode file has entries for 'forumEntry':
[ERROR] SCD "~forumEntry" didnt match any schema component
I guess it means 'forumEntry's not showing up 开发者_Python百科in WSDL, which is right:
<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 parts fit together here, to reuse the server side class?
You should add a ForumEntry class to the schema, so that the client can generate it, and use that generated class on your server side. Or add a new class to your schema that contains similar data to ForumEntry, and have the server create those objects on response from your ForumEntry objects, and return those created objects instead.
精彩评论