JAvax-service WebServiceインタフェースへのアクセス

6057 ワード

jarパッケージが必要です:
 ,jdk 

テスト:
package javax;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.spi.Provider;
import javax.xml.ws.spi.ServiceDelegate;
public class JAXWSClient {

    public static void main(String[] args) throws MalformedURLException {
        URL wsdlLocation = new URL("http://127.0.0.1:8087//services/WebServicesTest?wsdl");
        // 
        String namespaceURI = "webservices.wst.weaver.com.cn";
        // service :
        String serviceName = "WebServicesTest";
        // port :
        String portName = "WebServicesTestHttpPort";
        WebServicesTest result=(WebServicesTest) JAXWSClient.getServiceClass1(wsdlLocation, namespaceURI, serviceName, portName, WebServicesTest.class);
        System.out.println(result.getIN(132));
    }

    /**
     *  
     * @param wsdlLocation  WebService 
     * @param namespaceURI   
     * @param serviceName   service :
     * @param portName  port : @param className  
     * @return
     */
    public static Object getServiceClass(URL wsdlLocation,String namespaceURI,String serviceName,String portName,Class className){
        ServiceDelegate delegate = Provider.provider().createServiceDelegate(wsdlLocation,new QName(namespaceURI, serviceName),Service.class);
        return delegate.getPort(new QName(namespaceURI, portName), className);
    }

    /**
     *  
     * @param wsdlLocation  WebService 
     * @param namespaceURI   
     * @param serviceName   service :
     * @param portName  port : @param className  
     * @return
     */
    public static Object getServiceClass1(URL wsdlLocation,String namespaceURI,String serviceName,String portName,Class className){
        Service service = Service.create(wsdlLocation, new QName(namespaceURI, serviceName));
        return service.getPort(new QName(namespaceURI, portName), className);
    }

}

インタフェースのマッピング:
package javax;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name = "WebServicesTest", targetNamespace = "webservices.wst.weaver.com.cn")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface WebServicesTest {
    @WebMethod(operationName = "getIN1")
    @WebResult(name = "getIN1Response", partName = "getIN1Response")
    public String getIN1(
            @WebParam(name = "in0", partName = "in0") String in0);

    @WebMethod(operationName = "getIN")
    @WebResult(name = "getINResponse", partName = "getINResponse")
    public String getIN(
            @WebParam(name = "in0", partName = "in0") int in0);
}