我想了解如何使用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