首页>代码>SpringBoot WebService (CXF)简单入门实例>/SpringBootWebservice/WebserviceClient/src/main/java/com/simon/webserviceclient/controller/ClientController.java
package com.simon.webserviceclient.controller;

import com.simon.webserviceserver.service.ServerServiceDemo;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Simon
 */
@RestController
@RequestMapping("/client")
public class ClientController {

    @GetMapping("/proxy")
    public String invokeService_1() {
        String address = "http://localhost:9990/services/ws/api?wsdl";
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setAddress(address);
        jaxWsProxyFactoryBean.setServiceClass(ServerServiceDemo.class);
        ServerServiceDemo us = (ServerServiceDemo) jaxWsProxyFactoryBean.create();
        String data = "hello world";
        String result = us.testService(data);
        return result;
    }

    @GetMapping("/invoke")
    public String invokeService_2() {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient("http://localhost:9990/services/ws/api?wsdl");
        Object[] objects = new Object[0];
        try {
            objects = client.invoke("testService", "hello world");
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        }
        return objects[0].toString();
    }
}
最近下载更多
刘大大11  LV1 2022年8月7日
gaotieyou  LV5 2022年7月11日
pxqtsht  LV15 2022年2月25日
gchang  LV3 2022年2月20日
wsupsup  LV16 2021年12月2日
cc900118  LV17 2021年10月11日
最代码官方  LV167 2021年8月21日
最近浏览更多
lzx602  LV3 昨天
Luck_ZDM  LV11 4月12日
skook7  LV2 2023年12月14日
yuning1993  LV6 2022年11月7日
crosa_Don  LV18 2022年10月7日
刘大大11  LV1 2022年8月7日
sunshine9920  LV12 2022年7月22日
没猫病  LV11 2022年4月30日
liaozhenlei  LV8 2022年4月21日
gaotieyou  LV5 2022年4月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友