2012-08-03 2 views
3

기본 웹 서비스가 생성되었습니다. 내 서버 클래스에 "status"라는 변수가 있고 SEI에 클라이언트가 호출하여 상태를 가져 오는 "getUpdate"메소드가 들어 있다고 가정 해 보겠습니다. SEI 메서드 "getUpdate"를 호출하기 위해 이것을 클라이언트 측에서 어떻게 코딩해야합니까?SEI (Service Endpoint Interface)

클라이언트 측에서 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; 
    } 
} 

답변

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

주의하십시오.