• 01快速实现一个基于Jws的Webservice项目


    webservice

      异构平台之间的交互如:.net、php、python、perl

      流行的框架:CXF、Axis、Metro

      JAVA提供的:JAX-WS

    一、快速实现一个基于Jws的Webservice项目

      1、服务器的建立

        1.1创建接口

          

    package com.bling.service;
    
    import javax.jws.WebService;
    
    @WebService
    public interface IMyService {
        public int sum(int a,int b);
        
        public int minus(int a,int b);
    }

        1.2创建实现类

    package com.bling.service;
    
    import javax.jws.WebService;
    
    
    @WebService(endpointInterface="com.bling.service.IMyService")
    public class MyServiceImpl implements IMyService {
    
        @Override
        public int sum(int a, int b) {
            // TODO Auto-generated method stub
            System.out.println(a+"+"+b+" = "+(a+b));
            return a+b;
        }
    
        @Override
        public int minus(int a, int b) {
            // TODO Auto-generated method stub
            System.out.println(a+"+"+b+" = "+(a-b));
            return a-b;
        }
    
    }

        1.3开启服务

    package com.bling.service;
    
    import javax.xml.ws.Endpoint;
    
    public class MyService {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String address = "http://localhost:8888/ws";
            Endpoint.publish(address, new MyServiceImpl());
        }
    
    }

    可以生成一个wsdl的文件在服务地址中

      2.客户端建立

        

    package com.bling.service;
    
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import javax.xml.namespace.QName;
    import javax.xml.ws.Service;
    
    public class TestClient {
    
        public static void main(String[] args) throws MalformedURLException {
            // TODO Auto-generated method stub
            URL url = new URL("http://localhost:8888/ws?wsdl");
            QName sname= new QName("http://service.bling.com/","MyServiceImplService");
            Service service = Service.create(url,sname);
            IMyService ms = service.getPort(IMyService.class);
            System.out.println(ms.sum(10, 20));
            System.out.println(ms.minus(10, 20));
        }
    
    }

    输出:

      30
      -10

    GitBub源码地址:https://github.com/WebServcie/service_start

  • 相关阅读:
    AJAX
    JQUERY基础
    PHP 数据库抽象层pdo
    会话控制:session与cookie
    php 如何造一个简短原始的数据库类用来增加工作效率
    php 数据访问(以mysql数据库为例)
    面向对象设计原则
    php 设计模式 例子
    PHP中静态与抽象的概念
    键盘的按钮键名
  • 原文地址:https://www.cnblogs.com/yangml/p/3859445.html
Copyright © 2020-2023  润新知