WebService 基础知识点和用Postman调试

阅读连接:Retrofit 用Soap协议访问WebService 详解

参考

1、java发HTTP POST请求(内容为xml格式)
2、 android解析XML总结(SAX、Pull、Dom三种方式)
3、Android利用Soap读取WebService并且解析XML的DataSet数据

前言

1、首先不要把这个想的太复杂,它就是使用【soap】协议的请求,数据格式都是【xml】,基础还是http的post请求,但是它的规范显然更多一些,总体逃不过【Request和Response】。
2、以下所有的范例都是使用 【 WeatherWebService 】 这个网站,它提供了【Soap1.1 和 Soap1.2 】的请求范例,有【Request和Response】报文可看,这样更好理解规范和格式
注意点:
1、Soap1.1 、Soap1.2 :不同版本协议,代表的header和xml都略有不同
2、Baseurl、Header(Content-type、SOAPAction)、RequestBody(Xml)、ResponseBody(Xml)
3、RequestBody(Xml):Envelope,NameSpace、Body、Method、Param
3、ResponseBody(Xml):Envelope,NameSpace、Body、Method、Param

WebService 基础与注意点

举例:天气网站-获得某省份下所有城市

Soap1.1:

1、xmlns后基本都是namespace,比如envelopse标签有三个namespace,getSupportCity这个方法名有一个namespace
2、区分soap1.1的是:【xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"】
3、soap1.1的请求header有:【Content-Type: text/xml; charset=utf-8 】和【SOAPAction: "http://WebXml.com.cn/getSupportCity"】

//-------------------------------------Request------------------------------------
POST /WebServices/WeatherWebService.asmx HTTP/1.1
Host: www.webxml.com.cn
Content-Type: text/xml; charset=utf-8   //header中的哦~~
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getSupportCity"  //header中的哦~~

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  //标记为soap1.1协议
  <soap:Body>
    <getSupportCity xmlns="http://WebXml.com.cn/">  //method和其namespace
      <byProvinceName>string</byProvinceName>     //param
    </getSupportCity>
  </soap:Body>
</soap:Envelope>

//-------------------------------------Response------------------------------------
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getSupportCityResponse xmlns="http://WebXml.com.cn/">  //结果集啦~~
      <getSupportCityResult>
        <string>string</string>
        <string>string</string>
      </getSupportCityResult>
    </getSupportCityResponse>
  </soap:Body>
</soap:Envelope>
Soap1.2:

1、略,同上
2、区分soap1.2的是:【xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"】
3、soap1.2的请求header有:【application/soap+xml; charset=utf-8 】和没有【SOAPAction】

//-------------------------------------Requeset------------------------------------
POST /WebServices/WeatherWebService.asmx HTTP/1.1
Host: www.webxml.com.cn
Content-Type: application/soap+xml; charset=utf-8  //header中的,与soap1.1不同哦,而且没有soapaction了,需要注意~~~~
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> //标记为soap1.2协议
  <soap12:Body>
    <getSupportCity xmlns="http://WebXml.com.cn/">
      <byProvinceName>string</byProvinceName>
    </getSupportCity>
  </soap12:Body>
</soap12:Envelope>

//-------------------------------------Response------------------------------------
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <getSupportCityResponse xmlns="http://WebXml.com.cn/">  //结果集~~~
      <getSupportCityResult>
        <string>string</string>
        <string>string</string>
      </getSupportCityResult>
    </getSupportCityResponse>
  </soap12:Body>
</soap12:Envelope>

Postman调试(也可以用SoapUI)

soap1.1
1.png
2.png
3.png
soap1.2
5.png
6.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,099评论 19 139
  • 1. XML简介 以下内容来自于http://www.w3school.com.cn/xml 基本知识 XML 和...
    WebSSO阅读 1,974评论 1 7
  • WebService介绍 首先我们来谈一下为什么需要学习webService这样的一个技术吧.... 问题一 如果...
    Java3y阅读 9,677评论 5 139
  • Web Services(Web服务)是一个用于支持网络间不同机器互操作的软件系统,它是一种自包含、自描述和模块化...
    哇楼主阅读 903评论 0 7
  • 咏红梅花得“梅”字白梅懒赋赋红梅,逞艳先迎醉眼开。冻脸有痕皆是血,酸心无恨亦成灰。误吞丹药移真骨,偷下瑶池脱旧胎。...
    木夫009阅读 671评论 1 2