soap客户端调用wsdl接口

2017-05-29  本文已影响382人  69c673da4b91

本文主要以代码的形式展示以下具体如何调用wsdl接口(关于wsdl接口,本文不多做介绍了,可自行Google),本文的用例为camds相关接口的调用,出于安全,可能不会暴露一些关键信息。
一、首先以java调用为例:
1、maven依赖:

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency>
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.axis2.wso2/axis2 -->
    <dependency>
        <groupId>org.apache.axis2.wso2</groupId>
        <artifactId>axis2</artifactId>
        <version>1.6.1.wso2v10</version>
    </dependency>

2、插件,用于生成本地java类文件
```
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.maksim.ws</generatePackage>
<generateDirectory>${basedir}/src/main/java</generateDirectory>
<schemas>
<schema>
<fileset>

<directory>${basedir}/src/main/resources/schemas</directory>

<includes>
<include>*.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</plugin>

3、具体调用

package com.maksim;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

/**
* Created by maksim on 2017/5/16.
*/

@Configuration
public class WSConfig {
  @Bean
  public Jaxb2Marshaller marshaller() {
      Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
      marshaller.setContextPath("com.maksim.ws");
      return marshaller;
  }
  @Bean
  public WsClient wsClient(Jaxb2Marshaller marshaller) {
      WsClient client = new WsClient();
      client.setDefaultUri("http://****/CamdsWebService?wsdl");
      client.setMarshaller(marshaller);
      client.setUnmarshaller(marshaller);
      return client;
  }
}


  ```
            

        
二、PHP调用比较简单,只需要安装soapClient拓展即可,附上PHP调用例子,代码如下:
处理类

<?php

/**

上一篇 下一篇

猜你喜欢

热点阅读