SOAP接口对接

SOAP接口对接

SOAP协议

​ SOAP (简单对象访问协议)是基于xml格式简易协议,支持绑定http、tcp、udp协议进行网络信息交换。常见的是SOAP结合http构建rpc风格的传输,大致过程是SOAP消息基于xml进行编码,然后映射到http协议语义上,基于http协议进行消息的网络传输。(也可以将SOAP消息映射到tcp\udp上)

webservice

​ webservice由SOAP、WSDL、UDDI 组成,SOAP用来描述传递信息的格式、WSDL用来描述如何访问具体的接口,UDDI用来管理查询webservice。

spring webservice 实现

发布webservice

https://spring.io/guides/gs/producing-web-service/#initial

访问webservice

  1. 生成相应的服务依赖对象,通过服务发放地址(通常拼接上?wsdl)可以获取相应的wsdl文件,利用maven的 **maven-jaxb2-plugin**插件生成对象

    参考

    <build>
            <plugins>
                <!-- tag::wsdl[] -->
                <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.14.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                        <generatePackage>com.xxx.xxxxx</generatePackage>
                        <schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
                        <schemaIncludes>
                            <include>xx.wsdl</include>
                        </schemaIncludes>
    <!--                    <schemas>-->
    <!--                        <schema>-->
    <!--                            <url>http:xxxxxxxx?wsdl</url>-->
    <!--                        </schema>-->
    <!--                    </schemas>-->
                    </configuration>
                </plugin>
                <!-- end::wsdl[] -->
            </plugins>
        </build>
    
  2. 基于spring提供的webserviceTemplate 可以简单便捷的进行接口的请求

    依赖

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web-services</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            
    
  3. webserviceTemplate 使用

    WebServiceTemplate webServiceTemplate = new WebServiceTemplate() ;
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("com.xx.xxx");//marshaller 解析的时候会依赖这个类路径
    webServiceTemplate.setMarshaller(marshaller);
    webServiceTemplate.setUnmarshaller(marshaller);
    ObjectFactory objectFactory = new ObjectFactory();
    return ((JAXBElement<QueryPolicyInfoResponse>)webServiceTemplate.marshalSendAndReceive(url, objectFactory.createXXXX(xxxxx))).getValue();
    

参考

https://www.w3school.com.cn/soap/soap_intro.asp

https://baike.baidu.com/item/%E7%AE%80%E5%8D%95%E5%AF%B9%E8%B1%A1%E8%AE%BF%E9%97%AE%E5%8D%8F%E8%AE%AE/3841505?fromtitle=SOAP&fromid=4684413&fr=aladdin

https://spring.io/guides/gs/producing-web-service/#initial

https://docs.spring.io/spring-ws/site/reference/html/client.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值