cxf ServerFactoryBean 生成基於soap1.2的WebServices

Gyoung發表於2016-05-10
//獲得服務工廠bean
        ServerFactoryBean bean = new ServerFactoryBean();

        HTTPTransportFactory httpTransportFactory = new HTTPTransportFactory();
        //繫結服務的釋出地址
        bean.setAddress("http://10.0.1.32:5678/hello");
        //指定提供服務的型別
        bean.setServiceClass(HelloService.class);
        //指定提供服務的例項
        bean.setServiceBean(new HelloServiceImpl());

        bean.getServiceFactory().getConfigurations().add(new MethodNameSoapActionServiceConfiguration());

        SoapBindingConfiguration conf = new SoapBindingConfiguration();
        conf.setVersion(Soap12.getInstance());
        bean.setBindingConfig(conf);

        //啟動服務-----publish
        bean.setStart(false);
        ServerImpl server= (ServerImpl)bean.create();
        EndpointInfo e1=((ServletDestination)server.getDestination()).getEndpointInfo();

        e1.getBinding().getOperations().forEach(e->{

        });


        Bus b1=((ServletDestination)server.getDestination()).getBus();
        Destination destination= httpTransportFactory.getDestination(e1,b1);
        server.setDestination(destination);
        server.start();


        System.out.println("server ready...");

重點程式碼是

 SoapBindingConfiguration conf = new SoapBindingConfiguration();
        conf.setVersion(Soap12.getInstance());
        bean.setBindingConfig(conf);

 

相關文章