3

我创建了一个基本的 Web 服务。假设我的服务器类有一个名为“status”的变量,它的 SEI 包含一个方法“getUpdate”供客户端调用并获取状态?如何在客户端对此进行编码以调用 SEI 方法“getUpdate”?

如果我在客户端使用 port.Update 是什么意思,但我如何确定我指的是哪个服务器实例?

提前致谢。

SEI类:

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();
}

服务器类:

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;
    }
}
4

1 回答 1

2

您需要发布您创建的内容,以便您可以使用它。

 Endpoint.publish("http://localhost:port/webservicepack", new webServiceimplementationClass);

然后创建一个客户端。

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".

小心。

于 2014-02-13T09:53:51.613 回答