by

Consume a web service using Apache CXF client library

Apache CXF may also be used to consume a web service. Obviously, the match of client and server both with CXF make the development very simple, as the same IMyAPI interface may be used as a contract between server and client.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/38559/Consume-a-web-service-using-Apache-CXF-c?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import java.net.MalformedURLException; import java.net.URL; public class CxfClientImpl { private static final QName SERVICE_NAME = new QName("http://com.snip2code.api", "MyAPIService"); private static final QName PORT_NAME_DB = new QName("http://com.snip2code.api", "apiName"); private IMyAPI portAPI; public CxfClientImpl() { //initialize web service utilities: URL wsdlURL = null; String location = "http://192.168.1.5:1572/MyAPIService"; try { wsdlURL = new URL(location); } catch (MalformedURLException e) { log.error("Malformed Url:" + location + ", due to:" + e.getMessage()); return; } Service service = Service.create(SERVICE_NAME); service.addPort(SERVICE_NAME, SOAPBinding.SOAP11HTTP_BINDING, wsdlURL.toString()); portAPI = service.getPort(PORT_NAME, IMyAPI.class); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus