【WebService】通过postman请求web service

概述

用postman请求web service,在编写soap xml时,要区分soap(或http)的版本,不同的版本,有不同的请求方式。

具体写法参考这个文章标签下的其他文章。

解决方法

以soap1.1为例

1、postman用post方式,header上要设置:Content-Type:text/xml;charset=utf-8

2.请求报文体选择,body -> raw -> xml

3.请求报文

以版本1.1为例,请求报文有两种写法

方法一

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:cxf3="http://cxf3.what21.com/"
xmlns:aa="http://webservice.example.com/">
  <soap:Body>
    <aa:sayHello>
        <userName>青山</userName>
    </aa:sayHello>
  </soap:Body>
</soap:Envelope>

方法二

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:cxf3="http://cxf3.what21.com/">
  <soap:Body xmlns:aa="http://webservice.example.com/">
    <aa:sayHello>
        <userName>青山</userName>
    </aa:sayHello>
  </soap:Body>
</soap:Envelope>

其中,

xmlns:aa 属性的内容是服务端配置的命名空间(即,@WebService注解的targetNamespace属性),通过访问wsdl文档,也可以看到。

请求报文中xml的约束中,只有xmlns:soap和自定义(xmlns:aa)的命名空间(最)有用.

<aa:sayHello>是方法名,具体的说,只有sayHello是方法名。

<userName>是方法参数名,也是@WebParam()中name属性的设置值;而且不能加 aa: 这个前缀。

参考文章

https://blog.csdn.net/yysyangyangyangshan/article/details/86650012

猜你喜欢

转载自blog.csdn.net/xiaoxiao_su123/article/details/111480014