**My Web service class** import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class HelloWeb { @WebMethod public String sayGreeting(String name) { return "Greeting " + name + "....!"; } }
Java Server Class
import javax.xml.ws.Endpoint; public class Server { public static void main(String[] args) { Endpoint.publish("http://localhost:9090/HelloWeb", new HelloWeb()); System.out.println("Hello Web service is ready"); } }
The server is working correctly and I can access the service using the URL that returns the WSDL code. But I want to access the server using a unique URL in java.I have the following client java code:
Client for accessing the HelloWeb service
import java.net.URL; import javax.xml.namespace.QName; import javax.xml.rpc.Service; import javax.xml.rpc.ServiceFactory; public class WebClient { String wsdl = "http://172.21.1.65:9090/HelloWeb?wsdl"; String namespace = "http://helloweb.com"; String serviceName = "HelloWebService"; QName serviceQN = new QName(namespace, serviceName); { try{ ServiceFactory serviceFactory = ServiceFactory.newInstance(); Service service = serviceFactory.createService(new URL(wsdl), serviceQN); }catch (Exception e) { } } }
Edward sagayaraj
source share