客户端编程t调用Webservice

package com.cgm.clientservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;


/**
* This class was generated by the JAXWS SI.
* JAX-WS RI 2.0_02-b08-fcs
* Generated source version: 2.0
*
*/
@WebService(name = "WS_01", targetNamespace = "http://ws.cgm.com/")
public interface WS01 {


    /**
     *
     * @param arg0
     * @return
     *     returns java.lang.String
     */
    @WebMethod
    @WebResult(targetNamespace = "")
    @RequestWrapper(localName = "sayHello", targetNamespace = "http://ws.cgm.com/", className = "com.cgm.ws.SayHello")
    @ResponseWrapper(localName = "sayHelloResponse", targetNamespace = "http://ws.cgm.com/", className = "com.cgm.ws.SayHelloResponse")
    public String sayHello(
        @WebParam(name = "arg0", targetNamespace = "")
        String arg0);

}






package com.cgm.clientservice;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;


/**
* This class was generated by the JAXWS SI.
* JAX-WS RI 2.0_02-b08-fcs
* Generated source version: 2.0
*
*/
@WebServiceClient(name = "WS_01Service", targetNamespace = "http://ws.cgm.com/", wsdlLocation = "http://192.168.111.100:6789/hello?wsdl")
public class WS01Service
    extends Service
{

    private final static URL WS01SERVICE_WSDL_LOCATION;

    static {
        URL url = null;
        try {
            url = new URL("http://192.168.111.100:6789/hello?wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        WS01SERVICE_WSDL_LOCATION = url;
    }

    public WS01Service(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public WS01Service() {
        super(WS01SERVICE_WSDL_LOCATION, new QName("http://ws.cgm.com/", "WS_01Service"));
    }

    /**
     *
     * @return
     *     returns WS01
     */
    @WebEndpoint(name = "WS_01Port")
    public WS01 getWS01Port() {
        return (WS01)super.getPort(new QName("http://ws.cgm.com/", "WS_01Port"), WS01.class);
    }

}



package com.cgm.clientservice;

import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;



public class APP {

public static void main(String[] args) {

try {
URL ws=new URL("http://192.168.111.101:6789/hello?wsdl");
Service s= Service.create( ws, new QName("http://ws.cgm.com/","WS_01Service"));
WS01 hs= (WS01) s.getPort(new QName("http://ws.cgm.com/","WS_01Port"), WS01.class);
    String ss=hs.sayHello("ssssss");
      System.out.println(ss);
} catch (Exception e) {
e.printStackTrace();
}


}

}

你可能感兴趣的:(webservice)