服务端点接口(SEI)

时间:2012-08-03 02:03:00

标签: java web-services interface endpoint

我创建了一个基本的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;
    }
}

1 个答案:

答案 0 :(得分: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".

小心。