博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用JDK开发web service
阅读量:4180 次
发布时间:2019-05-26

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

服务器端

    编码:
        a. 创建一个基于jdk6以上版本的java工程
        b. 定义SEI web service Endpoint interface(web service终端接口)
            @WebService
            public interface HelloWS {
                @WebMethod
                public String sayHello(String name);
            }
        c. 定义SEI的实现类:
            @WebService
            public class HelloWSImpl implements HelloWS {
                @Override
                public String sayHello(String name) {
                    System.out.println("sayHello "+name);
                    return "hello "+name;
                }
            }
    发布:
        public class Server {
            public static void main(String[] args) {
                //客户端发送web service请求的url
               String address="http://127.0.0.1/tg_ws/helloWS";
                //处理请求的SEI对象
                HelloWS helloWS = new HelloWSImpl();
                //发布web service
                Endpoint.publish(address, helloWS);
                System.out.println("发布web service成功!");
            }
        }

   (注:我的要建一个ServerDelegate  在Server基础上点击 打开new=》other=》输入 web service 点击=》选择 create web service from java class=》打开Brouwse 输入你的测试类 最后勾上 Generate WSDL in project   会生成一个 * Delegate.java)

②. 客户端

    1. eclipse Web Service浏览器
        a. 查看Web Service所对应的WSDL文档:...?wsdl
        b. 使用eclipse访问
            请求体:SOAP Request Envelope
                <soapenv:Envelope>
                    <soapenv:Body>
                        <q0:sayHello>
                            <arg0>tt</arg0>
                        </q0:sayHello>
                    </soapenv:Body>
                </soapenv:Envelope>
            响应体:SOAP Response Envelope
                <S:Envelope>
                    <S:Body>
                        <ns2:sayHelloResponse xmlns:ns2="http://ws.java.atguigu.net/">
                            <return>hello tt</return>
                        </ns2:sayHelloResponse>
                    </S:Body>
                 </S:Envelope>

    2. 编码实现

        a. 创建客户端java应用
        b. 在应用的src下执行cxf的命令生成客户端代码:
            wsimport -keep http://127.0.0.1/tg_ws/helloWS?wsdl
        c. 编写客户端调用的测试代码,执行:
            public class Client {
                public static void main(String[] args) {
                    //创建SEI的工厂对象
                    HelloWSImplService factory = new HelloWSImplService();
                    //得到一个SEI实现类对象
                    HelloWSImpl helloWS = factory.getHelloWSImplPort();
                    //调用SEI的方法,此时才去发送web Service请求,并得到返回结果
                    String result = helloWS.sayHello("Tom");
                    System.out.println(result);
                }
            }
                    
        ③.请求过程记录:使用eclipse的tcp/ip工具进行请求的监控

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

你可能感兴趣的文章
在Ubuntu Server上编译FFmpeg
查看>>
git 切换到远程分支
查看>>
AAC的ADTS头文件信息介绍
查看>>
CMAKE手册
查看>>
Doubango RTP包传输使用UDT可靠传输协议,解决RTP丢包问题
查看>>
Android手机H264软编码参数优化
查看>>
将AAC格式的RTP流存储为可以播放的m4a文件
查看>>
UDT协议-基于UDP的可靠数据传输协议
查看>>
[FFMPEG硬件加速]nvidia方案
查看>>
openal播放裸数据
查看>>
OpenAL对象属性
查看>>
OpenAL 3D效果营造
查看>>
librtmp协议分析---RTMP_SendPacket函数
查看>>
视频学习笔记:Android ffmpeg解码多路h264视频并显示
查看>>
关于对H264码流的TS的封装的相关代码实现
查看>>
PortAudio+webrtc+lame实现采集降噪增益mp3
查看>>
视频压缩编码和音频压缩编码的基本原理
查看>>
利用FFmpeg玩转Android视频录制与压缩(二)
查看>>
利用FFmpeg玩转Android视频录制与压缩(三)
查看>>
windows10 编译x264出现 undefined reference to `_beginthreadex'解决
查看>>