6

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

1 Answer 1

-1

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.

3
  • thanks, but could you be more specific? I'm returning a List, while FourmEntry's a type. How can both sides use the Forumentry class? Thanks.
    – Andrew
    May 15, 2011 at 14:50
  • You'd have to generate the ForumEntry class on the client side and use that. May 15, 2011 at 18:13
  • 1
    Though this question is old, but I have similar question. The problem is that I already have a bunch of server side code using some classes as data types, and also a bunch of utility methods in those classes. If the server sides change to use the generated class from the client, it would be a major work... Nov 16, 2015 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.