我想了解如何使用Java自己理解创建自己的Web服务。Java Web服务WSDL加载但不是web服务
当我到localhost:9998/calculate?wsdl我可以看到我的wsdl文件,但是当我到localhost:9998 /计算我看不到我的web服务。我只是在chrome中出现错误,说ERR_EMPTY_RESPONSE localhost没有发送任何数据。
这里是我的接口:
package Webservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
//Service Endpoint Interface
@WebService
public interface Calculate{
@WebMethod
public int add(int x, int y);
@WebMethod
public int sub(int x, int y);
@WebMethod
public int mul(int x, int y);
}
这里是我的接口的实现:
package Webservice;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "Webservice.Calculate")
public class CalculateImpl implements Calculate {
public CalculateImpl() {
}
@Override
public int add(int x, int y) {
return (x+y);
}
@Override
public int sub(int x, int y) {
return (x-y);
}
@Override
public int mul(int x, int y) {
return (x*y);
}
}
,这里是我的出版商:
package Webservice;
import javax.xml.ws.Endpoint;
public class CalculatePublisher {
public static void main(String[] args) {
Endpoint ep = Endpoint.create(new CalculateImpl());
ep.publish("http://localhost:9998/calculate");
}
}
任何帮助,将不胜感激。
WSDL表示SOAP服务。每个服务操作都要求HTTP请求是一个SOAP调用,这与通过在浏览器中输入URL所做的普通HTTP GET请求不同。请参阅https://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383526和https://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383539。 – VGR