1

为了学习如何做,我正在尝试设置我的第一个示例 Web 项目。我在一个名为“com.java24hours.ws”的包中有 4 个类。我正在尝试将 Eclipse 中的 SquareRootClient 类作为 java 应用程序运行。我收到一个 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));
    }
}

平方根服务器

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
4

0 回答 0