java调用wcf soap协议接口

java  调用wcf协议接口

1.        添加pom:

<dependency>

<groupId>org.apache.cxfgroupId>

<artifactId>cxf-rt-frontend-jaxwsartifactId>

<version>3.5.0version>

dependency>

<dependency>

<groupId>org.apache.cxfgroupId>

<artifactId>cxf-rt-transports-httpartifactId>

<version>3.5.0version>

dependency>

2.        客户端:

public static void cxfClient(){

    //  访问地址

    String address = "http://1.1.1.1/xxx?wsdl";

    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();

    Client client = dcf.createClient(address);

    // 用户登录认证

    // client.getOutInterceptors().add(new ClientLoginInterceptor("",""));

    try {

        //  从哪个接口获取数据  写方法名

        Object[] objs = client.invoke("GetId");

        //   传参并获取数据

        Map map = new HashMap();

        map.put("a",1);

        Object[] objs2 = client.invoke("GetId", map);

        System.out.println(objs);

        System.out.println(objs2);

    } catch (Exception e) {

        e.printStackTrace();

    }

}

3.        登录拦截器 (不用验证就不用写!!!

import org.apache.cxf.binding.soap.SoapMessage;

import org.apache.cxf.interceptor.Fault;

import org.apache.cxf.phase.AbstractPhaseInterceptor;

import org.apache.cxf.phase.Phase;

public class ClientLoginInterceptor extends AbstractPhaseInterceptor<SoapMessage> {

    private String username;

    private String password;

    public ClientLoginInterceptor(String username, String password) {

        super(Phase.PREPARE_SEND);

        this.username=username;

        this.password = password;

    }

    @Override

    public void handleMessage(SoapMessage message) throws Fault {

       message.getHeaders();

       //  拿出自己要验证的字段  写业务逻辑

    }

}

4.  发布端

不会 !!!

都什么年代了 这个还有人用这个协议  快跑路吧 !  

你可能感兴趣的:(java,java,开发语言,后端,wcf,soap)