Reputation: 81
I have a basic web service created. Let's say my server class has a variable called "status", and its SEI contain a method "getUpdate" for client to call and get the status? How do I code this out at the client side to call the SEI method "getUpdate"?
What I mean if I use port.Update at the client side but how do I determine which server instance I am referring to?
Thanks in advance.
SEI class:
package com.basic.ws;
import javax.jws.WebService;
@WebService(name = "Server_SEI", targetNamespace = "http://ws.basic.com/")
public interface Server_SEI {
public int sum(int x, int y);
public String getUpdate();
}
Server class:
package com.basic.ws;
import javax.jws.WebService;
@WebService(targetNamespace = "http://ws.basic.com/", endpointInterface = "com.basic.ws.Server_SEI", portName = "ServerPort", serviceName = "ServerService")
public class Server implements Server_SEI{
String status = "OK";
public void setTrafficStatus(String status){
this.status = status;
}
public String getUpdate(){
return status;
}
}
Upvotes: 3
Views: 13386
Reputation: 194
You need to publish what you have created so that you can consume it.
Endpoint.publish("http://localhost:port/webservicepack", new webServiceimplementationClass);
Then create a client.
URL url = new URL("http://localhost:port/webServicepack?wsdl");
//here is the service consuming
QName qName = new QName("http://webservicepackage/", "webserviceimplementationsclass");
// Qualified name of the service:
// 1st arg is the service URI
// 2nd is the service name published in the WSDL
Service service = Service.create(url, qName);
// Create, in effect, a factory for the service.
TimeServer eif = service.getPort(ServiceClient.class);
// Extract the endpoint interface, the service "port".
Take care.
Upvotes: 2