views:

7629

answers:

4

I have a very simple soap web service that I need to consume from a Java client. What is the easiest way to accomplish this without using any third party libraries? A requirement is that the host anhd port is read from the web.xml before every call to the ws.

A: 

Without using any third party libraries? Get to know the SOAP standard really well and learn to love SAX.

If you can't love SAX, then lax your no-third-party-libs requirement and use StAX (with woodstox) instead.

This approach might be the "easiest" (considering the no-third-party-libs requirement) but I don't think it will be easy.

Christian Vest Hansen
I don't understand why it would be so difficult? Surely all you have to do is construct the request using a stringbuffer, open a connection then stuff the request down the connection and wait for a response. Or am I missing something here?
Deano
What you may be missing is the difficulty/tedium of constructing the request using StringBuffer. It`s certainly possibly, but I wouldn`t recommend it. The same goes for reading the response without a SOAP library.
Don
+2  A: 

If youo can relax your "no 3rd party libraries" requirement, and you have a WSDL for the web service then Axis makes it really easy. Just compile the WSDL using wsdl2java, and you can use the generated Java classes to consume the web service.

Don
+3  A: 

hi there,

depending on which version of JAVA you're using, some of the JAX-WS is built into it. JDK 6 has java's JAX-WS standard implementation and you could just use it.

SEE the following

http://weblogs.java.net/blog/ramapulavarthi/archive/2008/01/jaxws_21_and_ja.html

http://www.netbeans.org/kb/60/websvc/jax-ws.html -- tutorial to use the JDK built-in JAX-WS for deploying and consuming a web service.

BR, ~A

anjanb
JAX-WS does look very easy to use, but how can it be used to read the host name from the web.config file?
Deano
+2  A: 

I can recommend you CXF library. Using it you will have several options for calling web services:

  • use dynamic proxy for calling

    DynamicClientFactory dcf = DynamicClientFactory.newInstance(); Client client = dcf.createClient("http://admin:password@localhost:8080/services/MyService?wsdl"); Object[] a = client.invoke("test", ""); System.out.println(a);

  • using Java stub generated from wsdl

  • if your server was created using CXF you can reuse your code:

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setUsername("admin"); factory.setPassword("password");
    factory.setAddress("http://admin:password@localhost:8080/services/MyService"); factory.setServiceClass(ITest.class); IDictionaryCurrency client = (ITest) factory.create(); client.test();

FoxyBOA
Does the DynamicClientFactory require you to create the stub first?
vikasde
No, you can dynamically execute methods from wsdl file, pass parameters, got result (scalar or xml object).
FoxyBOA