博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JAVA WebService开发入门引入
阅读量:4297 次
发布时间:2019-05-27

本文共 3021 字,大约阅读时间需要 10 分钟。

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);
    }
}

转载地址:http://xgcws.baihongyu.com/

你可能感兴趣的文章
python multiprocessing遇到Can’t pickle instancemethod问题
查看>>
APP真机测试及发布
查看>>
iOS学习之 plist文件的读写
查看>>
通知机制 (Notifications)
查看>>
10 Things You Need To Know About Cocoa Auto Layout
查看>>
C指针声明解读之左右法则
查看>>
一个异步网络请求的坑:关于NSURLConnection和NSRunLoopCommonModes
查看>>
iOS 如何放大按钮点击热区
查看>>
ios设备唯一标识获取策略
查看>>
获取推送通知的DeviceToken
查看>>
Could not find a storyboard named 'Main' in bundle NSBundle
查看>>
CocoaPods安装和使用教程
查看>>
Beginning Auto Layout Tutorial
查看>>
block使用小结、在arc中使用block、如何防止循环引用
查看>>
iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
查看>>
iOS开发中遇到的问题整理 (一)
查看>>
Swift code into Object-C 出现 ***-swift have not found this file 的问题
查看>>
为什么你的App介绍写得像一坨翔?
查看>>
RTImageAssets插件--@3x可自动生成@2x图片
查看>>
iOS开发的一些奇巧淫技
查看>>