zoukankan      html  css  js  c++  java
  • webService

    什么是webService 
    WebService,顾名思义就是基于Web的服务。它使用Web(HTTP)方式,接收和响应外部系统的某种请求。从而实现远程调用.  
    1:从WebService的工作模式上理解的话,它跟普通的Web程序(比如ASP、JSP等)并没有本质的区别,都是基于HTTP传输协议的程序。  
    2:WebService所使用的数据均是基于XML格式的。目前标准的WebService在数据格式上主要采用SOAP协议。SOAP协议实际上就是一种基于XML编码规范的文本协议。

     方案一:在地址栏输入URL,http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl


    方案二:通过Java代码实现

    打开cmd命令:------》cd到c盘根目录------》wsimport -s . http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl。并在C盘根目录下生成一系列java类。并运用到项目中,进行测试

     测试类:

    public class MyTest {
    public static void main(String[] args) {
        MobileCodeWS ws=new MobileCodeWS();
        MobileCodeWSSoap soap=ws.getMobileCodeWSSoap();
        String address=soap.getMobileCodeInfo("13225788", "");
        System.out.println(address);
    }
    }
    

      

      


    方案三:使用JAX-WS发布服务

    ①定义服务器类以及方法[HelloService]

    使用@WebService注解,标识一个java类或一个接口作为一个服务

    /*
     * @WebService注解,标识一个java类或一个接口作为一个服务,一旦被标注@WebService,他就不是一个普通的
     * 接口,他被称作服务端点接口(Service Endpoint Interface)
     */
    @WebService
    public class HelloService {
     
        public void say(String name) {
            System.out.println("hello" + name);
        }
     
        public static void main(String[] args) {
            Endpoint.publish("http://192.168.0.2:40000/hello", new HelloService());
            System.out.println("server is listening...");
        }
    }
    

      

     服务正在监听...

    在浏览器中测试:

    ② 同理 cmd命令解析该文档的类或方法[客户端]

    新建一个工程,运用这些类,进行测试

     

     MyTest测试类:

    public class MyTest {
    public static void main(String[] args) {
        HelloServiceService service=new HelloServiceService();
        HelloService hs = service.getHelloServicePort();
        hs.say("逗比");
    }
    }

      

  • 相关阅读:
    ASP.NET26 个常用性能优化方法
    git 合并 二进制文件
    git 状态管理
    git 分支管理,提交到远程服务器上面
    git 发布android 系统版本 修改版本型号 查看指定文件的修改记录
    使用git 发布android系统版本 1
    提取文本当中的汉字
    wpf 命名空间中不存在
    c# 调用c DLL 所传参数不正确
    用于主题检测的临时日志(233d1263-3c3c-43d0-a2fd-318ee6fd58db
  • 原文地址:https://www.cnblogs.com/baixingqiang/p/6188038.html
Copyright © 2011-2022 走看看