springboot用CXF动态调用webservice

axis搭建的webservice项目,

<service name="HelloWorld" provider="java:RPC" style="document" use="literal">
    <parameter name="className" value="example.HelloWorld"/>
    <parameter name="allowedMethods" value="*"/>
    <parameter name="scope" value="Application"/>
    <namespace>http://example</namespace>
</service>

客户端用CXF来调用

@Value("${webservice.url:127.0.0.1}")
private String url;


@Bean
public Client wsClient() {
    //创建动态客户端
    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    Client client = dcf.createClient(url);
    //需要密码的情况
    // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,
    // PASS_WORD));

    return client;
}

调用时报错:

org.apache.cxf.interceptor.Fault: Unexpected element {http://example}fromReturn found.   Expected {http://example}sayHelloWorldFromReturn.

然后,将style和use做修改:

<service name="HelloWorld" provider="java:RPC" style="rpc" use="encoded">
    <parameter name="className" value="example.HelloWorld"/>
    <parameter name="allowedMethods" value="*"/>
    <parameter name="scope" value="Application"/>
    <namespace>http://example</namespace>
</service>
,就正常了,搜了相关资料,都没说出个大概,此记已警。


猜你喜欢

转载自blog.csdn.net/genghongsheng/article/details/80522315