Maneesh
Maneesh

Reputation: 6128

How to consume a php web service in java

I need to consume with Java a web service created in PHP (SOAP). Is it the same as posting the web service URL with XML content or do I need to use something like below code?

String wsdlURL = "http://cxrus020:8080/HelloWebService/" + "HelloWS?wsdl";
String namespace = "urn:HelloWS/wsdl";
String serviceName = "HelloWS";
QName serviceQN = new QName(namespace, serviceName);

ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(new
URL(wsdlURL), serviceQN);
Call call = service.createCall();
call.setPortTypeName(serviceQN);
call.setOperationName(new QName(namespace, "greet"));
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");

call.addParameter("string_1",serviceQN,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(serviceQN);
Object[] inParams = new Object[]{"weetat is testing"};
String ret = (String) call.invoke(inParams);
System.out.println("ret:" + ret);

Upvotes: 1

Views: 3117

Answers (1)

Shimi Bandiel
Shimi Bandiel

Reputation: 5747

Consuming a web service is not dependent on the implementation technology of the WS (by definition of interoperability).

You can use the JAX-WS wsimport utility to generate the stubs and use them as you would for a web service in Java (or any other language).

Remember that all you need to know about the WS is its WSDL.

Upvotes: 6

Related Questions