java 服务端点接口 (SEI)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11788276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 06:21:39  来源:igfitidea点击:

Service Endpoint Interface (SEI)

javaweb-servicesinterfaceendpoint

提问by keithwb

I have a basic web service created. Let's say my server class has a variable called "status", and its SEI contain a method "getUpdate" for client to call and get the status? How do I code this out at the client side to call the SEI method "getUpdate"?

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

What I mean if I use port.Update at the client side but how do I determine which server instance I am referring to?

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

Thanks in advance.

提前致谢。

SEI class:

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

Server class:

服务器类:

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

回答by GiorgoCH

You need to publish what you have created so that you can consume it.

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

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

Then create a client.

然后创建一个客户端。

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

Take care.

小心。