その方法を学ぶために、最初のサンプル Web プロジェクトをセットアップしようとしています。「com.java24hours.ws」というパッケージに 4 つのクラスがあります。Java アプリケーションとして Eclipse で SquareRootClient クラスを実行しようとしています。java.net.ConnectException が発生しています (クラスの後にエラー ログを投稿しました)。誰が私が間違っているのか教えてもらえますか?
SquareRootClient
package com.java24hours.ws;
import java.net.*;
import javax.xml.namespace.*;
import javax.xml.ws.*;
class SquareRootClient {
public static void main(String[] arguments) throws Exception {
URL url = new URL("http://127.0.0.1:5335/service?wsdl");
QName qname = new QName(
"http://ws.java24hours.com/",
"SquareRoorServerImplService"
);
Service service = Service.create(url, qname);
SquareRootServer srs = service.getPort(SquareRootServer.class);
System.out.println(srs.getTime());
System.out.println(srs.getSquareRoot(625D));
}
}
SquareRootServer
package com.java24hours.ws;
import javax.jws.*;
import javax.jws.soap.*;
import javax.jws.soap.SOAPBinding.*;
@WebService
@SOAPBinding(style = Style.RPC)
public interface SquareRootServer {
// get the square root of a number
@WebMethod double getSquareRoot(double input);
// get the current time and date as a string
@WebMethod String getTime();
}
SquareRootServerImpl
package com.java24hours.ws;
import java.util.*;
import javax.jws.*;
@WebService(endpointInterface = "com.java24hours.ws.SquareRootServer")
public class SquareRootServerImpl implements SquareRootServer {
public double getSquareRoot(double input) {
return Math.sqrt(input);
}
public String getTime() {
Date now = new Date();
return now.toString();
}
}
SquareRootServerPublisher
package com.java24hours.ws;
import javax.xml.ws.*;
public class SquareRootServerPublisher {
public static void main (String [] arguments ){
SquareRootServerImpl srsi = new SquareRootServerImpl();
Endpoint.publish("http://127.0.0.1:5335/service", srsi);
}
}
コンソール (ログ):
Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://127.0.0.1:5335/service?wsdl. It failed with:
Connection refused: connect.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at javax.xml.ws.Service.create(Unknown Source)
at com.java24hours.ws.SquareRootClient.main(SquareRootClient.java:14)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(Unknown Source)
... 8 more