Im pretty new to Java Web Services, but I cant find a good explanation anywhere.
I have 2 Java web projects within NetBeans.
One as a web service and one as a client for that web service.
I have also created my own class called "Person", which has what you'd expect: name, dob, etc.
I would like to have a web service method called "ListPeople()" that would return an array of "Person" objects.
Do I need to have that class in both projects?
Should I be serializing the object first?
Should I be using JAXB, if so, where do I start?
Sorry for the n00b questions, but im confused.
What is the normal way of accomplishing this?
Thanks in advance
- Do I need to have that class in both projects? Yes.
- Should I be serializing the object first? No.
- Should I be using JAXB, if so, where do I start? I would not. I prefer the javax.oxm interfaces, because I don't care for JAXB, but that's a personal opinion.
My personal preference is to use Spring web services. If you happen to be a Spring user, I think that's the best way to go. If not, perhaps the docs will still help to clarify.
You're experiencing the reason why I don't like your approach: both the service and client and dependent on the class and OXM code. You have to have it in both places, in perfect synchronization. Change one and you have to change both.
I try to minimize dependencies if I can.
And in this case you can if you send XML back and forth. Start with an XSD schema. Let the client and service deal with that instead of Java objects. Your service will be usable for clients that aren't Java that way.
If you take this approach, you only have to worry about OXM on the server side. You take in the XML request and marshal it into the Java object of your choice and pass it to your service layer (note: NOT web service layer) for processing. Turn the response object into XML response stream and Bob's your uncle. Let the client deal with that.