WebService

webService实例:

service:

接口

public interface Business {
  public String echo(String message);
}

接口实现

@WebService(name = "Business", serviceName = "BusinessService", 
targetNamespace = "http://com.shangfi.javabase.webservice.webservice/client")
@SOAPBinding(style=SOAPBinding.Style.RPC)
public class BussinessImpl implements Business {


public String echo(String message) {
message="message demo";
return "Server response:" + message;
}
}

接口发发布

 /**
 * @author Administrator
 *  自动生成 代码  wsimport -keep http://localhost:8080/ShingFi/com/shangfi/javabase/webservice.webservice?wsdl
 */
public class Server {
public static void main(String[] args) throws Exception {
Endpoint.publish(
"http://localhost:8080/ShingFi/com/shangfi/javabase/webservice.webservice",
new BussinessImpl());
System.out.println(" Server Start");
}
}

client:

 用户命令来生成代码:wsimport -keep http://localhost:8080/ShingFi/com/shangfi/javabase/webservice.webservice?wsdl

生成如何

 /**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.1.6 in JDK 6
 * Generated source version: 2.1
 * 
 */
@WebService(name = "Business", targetNamespace = "http://com.shangfi.javabase.webservice.webservice/client")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface Business {




    /**
     * 
     * @param arg0
     * @return
     *     returns java.lang.String
     */
    @WebMethod
    @WebResult(partName = "return")
    public String echo(
        @WebParam(name = "arg0", partName = "arg0")
        String arg0);


}

**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.1.6 in JDK 6
 * Generated source version: 2.1
 * 
 */
@WebServiceClient(name = "BusinessService", targetNamespace = "http://com.shangfi.javabase.webservice.webservice/client", wsdlLocation = "http://localhost:8080/ShingFi/com/shangfi/javabase/webservice.webservice?wsdl")
public class BusinessService
    extends Service
{


    private final static URL BUSINESSSERVICE_WSDL_LOCATION;
    private final static Logger logger = Logger.getLogger(com.shangfi.javabase.webservice.webservice.client.BusinessService.class.getName());


    static {
        URL url = null;
        try {
            URL baseUrl;
            baseUrl = com.shangfi.javabase.webservice.webservice.client.BusinessService.class.getResource(".");
            url = new URL(baseUrl, "http://localhost:8080/ShingFi/com/shangfi/javabase/webservice.webservice?wsdl");
        } catch (MalformedURLException e) {
            logger.warning("Failed to create URL for the wsdl Location: 'http://localhost:8080/ShingFi/com/shangfi/javabase/webservice.webservice?wsdl', retrying as a local file");
            logger.warning(e.getMessage());
        }
        BUSINESSSERVICE_WSDL_LOCATION = url;
    }


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


    public BusinessService() {
        super(BUSINESSSERVICE_WSDL_LOCATION, new QName("http://com.shangfi.javabase.webservice.webservice/client", "BusinessService"));
    }


    /**
     * 
     * @return
     *     returns Business
     */
    @WebEndpoint(name = "BusinessPort")
    public Business getBusinessPort() {
        return super.getPort(new QName("http://com.shangfi.javabase.webservice.webservice/client", "BusinessPort"), Business.class);
    }


    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns Business
     */
    @WebEndpoint(name = "BusinessPort")
    public Business getBusinessPort(WebServiceFeature... features) {
        return super.getPort(new QName("http://com.shangfi.javabase.webservice.webservice/client", "BusinessPort"), Business.class, features);
    }
}

 client调用

 public class Client {
public static void main(String[] args) throws Exception {
BusinessService businessService = new BusinessService();
Business business = businessService.getBusinessPort();
String message = business.echo("test");
System.out.println(" Client Start");
System.out.println(message);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值