I want to know how to create web service. I am an android developer. Which method is suitable in android web services, actually we are using server side apache tomcat in PostgreSQL so please give me any ideas about this issues
问题:
回答1:
Presuming that by "web service" you mean one of the most common methods currently used, REST-style HTTP+JSON or HTTP+XML, you probably want to use JAX-RS (JSR311). This is part of the Java EE specification, and the easiest way to get going is to just use JBoss AS 7 which bundles it. JAX-RS implementations are also easy to use with Tomcat if you prefer Tomcat. You want RESTEasy or Jersey; either should be fine. Check out the Java EE tutorial for JAX-RS, the Jersey getting started guide, and the RESTEasy documentation.
If, in fact, you want some other kind of web service like XML-RPC, SOAP or CORBA (edit: as your post tags suggest), then (a) reconsider, they're being superceded for a reason and (b) if you must use them, look into implementations specific to the binding technology you must use. I'd suggest that you examine JAX-WS for SOAP+WSDL, but I haven't worked with it myself so I have nothing further to offer. I know the NetBeans IDE offers some kind of old-school SOAP/JAX-WS web services support, but again haven't looked into it.
I expect it'll be way easier to work with JAX-RS in Android than it will be to work with SOAP. A JAX-RS client doesn't need to be anything more than a HTTP client library and an XML or JSON parser/writer - though client libraries that target REST-style APIs exist and make them even easier to work with.
Do you really need SOAP? Or do you just need any kind of web based client/server communication? What exactly are you trying to achieve with this? Where does PostgreSQL come into it?
回答2:
I'm not entirely sure what's being asked here and I find it likely that this question will be closed any minute now, but here goes.
If you have problems in implementing a SOAP client in Android, see this question in Stack Overflow. The highest voted answer there states that Android doesn't have any native SOAP libraries but you can use something like kSOAP 2.
If it's the server part that's troubling you, see, for example, this tutorial. It's a lengthy one and relies heavily on images so I'm not going to even attempt summarizing it. Try implementing your service using the instructions provided there (and elsewhere) and get back to Stack Overflow once you have some code to show for us.