JAVA WebService开发入门引入

package com.hyan.service;

import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class HelloService {
    /**
     * 供客户端调用的方法
     * @param name                传入参数
     * @return String            返回结果
     */
    public String getValue(String name){
        return "我叫:"+name;
    }
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:9001/Service/HelloService", new HelloService());
        System.out.println("service 调用成功!");
    }
}

进行编译

说明:编译失败的话,请将该项目引用的jdk设置为1.6.0_17版本或更高版本

测试结果

测试地址:http://localhost:9001/Service/HelloService?wsdl



客户端测试

package com.hyan.test;

import com.hyan.client.ServiceHello;
import com.hyan.client.ServiceHelloService;

public class ServiceTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        HelloService hello = new ServiceHelloService().getServiceHelloPort();    
        String name = hello.getValue("Hyan");
        System.out.println(name);
    }
}




package com.hyan.client;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;


/**
 * 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 = "ServiceHelloService", targetNamespace = "http://service.hyan.com/", wsdlLocation = "http://localhost:9001/Service/ServiceHello?wsdl")
public class ServiceHelloService
    extends Service
{

    private final static URL SERVICEHELLOSERVICE_WSDL_LOCATION;
    private final static Logger logger = Logger.getLogger(com.hyan.client.ServiceHelloService.class.getName());

    static {
        URL url = null;
        try {
            URL baseUrl;
            baseUrl = com.hyan.client.ServiceHelloService.class.getResource(".");
            url = new URL(baseUrl, "http://localhost:9001/Service/ServiceHello?wsdl");
        } catch (MalformedURLException e) {
            logger.warning("Failed to create URL for the wsdl Location: 'http://localhost:9001/Service/ServiceHello?wsdl', retrying as a local file");
            logger.warning(e.getMessage());
        }
        SERVICEHELLOSERVICE_WSDL_LOCATION = url;
    }

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

    public ServiceHelloService() {
        super(SERVICEHELLOSERVICE_WSDL_LOCATION, new QName("http://service.hyan.com/", "ServiceHelloService"));
    }

    /**
     *
     * @return
     *     returns ServiceHello
     */
    @WebEndpoint(name = "ServiceHelloPort")
    public ServiceHello getServiceHelloPort() {
        return super.getPort(new QName("http://service.hyan.com/", "ServiceHelloPort"), ServiceHello.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 ServiceHello
     */
    @WebEndpoint(name = "ServiceHelloPort")
    public ServiceHello getServiceHelloPort(WebServiceFeature... features) {
        return super.getPort(new QName("http://service.hyan.com/", "ServiceHelloPort"), ServiceHello.class, features);
    }

}




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值