使用 SOAP Web 服务错误(未注册编组器.检查 WebServiceTemplate 的配置) [英] Consuming a SOAP web service error (No marshaller registered. Check configuration of WebServiceTemplate)

查看:21
本文介绍了使用 SOAP Web 服务错误(未注册编组器.检查 WebServiceTemplate 的配置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了入门 - 使用 SOAP 网络服务 (https://spring.io/guides/gs/sumption-web-service/) 来使用特定的网络服务并且一切正常:

I've followed the Getting Started - Consuming a SOAP web service (https://spring.io/guides/gs/consuming-web-service/) to consume a specific web service and everything works well:

我已经制作了配置类:

@Configuration
public class PMConfiguration {
    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // this package must match the package in the <generatePackage> specified in
        // pom.xml
        marshaller.setContextPath("com.inteligenciaweb.wsdl");
        return marshaller;
    }

    @Bean
    public ProcuraPMPorREClient procuraPMPorREClient(Jaxb2Marshaller marshaller) {
        ProcuraPMPorREClient client = new ProcuraPMPorREClient();
        client.setDefaultUri("http://tempuri.org/procuraPMPorRE");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        return client;
    } 

}

客户:

public class ProcuraPMPorREClient extends WebServiceGatewaySupport {

    private static final Logger log = LoggerFactory.getLogger(ProcuraPMPorRE.class);


    public ProcuraPMPorREResponse getPMPorRE(Integer RE) {

        ProcuraPMPorRE request = new ProcuraPMPorRE();
        request.setPMRENum(RE);

        log.info("Requesting PM for " + RE);

        ProcuraPMPorREResponse response = (ProcuraPMPorREResponse) getWebServiceTemplate()
                .marshalSendAndReceive("http://webservices.externo.policiamilitar.sp.gov.br:8071/router/wsscpm/basic",
                        request,
                        new SoapActionCallback("http://tempuri.org/procuraPMPorRE"));

        return response;
    }

}

在课堂上申请:

@SpringBootApplication
public class InteligenciawebApplication {

    public static void main(String[] args) {
        SpringApplication.run(InteligenciawebApplication.class, args);
    }

    @Bean
    CommandLineRunner lookup(ProcuraPMPorREClient pm) {
        return args -> {
            Integer re = 123456;        
            ProcuraPMPorREResponse response = pm.getPMPorRE(re); 
            System.err.println(response.getProcuraPMPorREResult().getNomeBancoPM());
        };
    }
}

当我启动一个应用程序时,weservice 调用工作正常,所以我可以在控制台看到结果.我尝试使用相同的逻辑在其他类中调用此 Web 服务,但不起作用.例如,我在控制器类做了一个测试:

When I start a application, the weservice calling works fine, so I can see the result at the console. I've tried to use the same logic to call this web service in other class, but isn't working. For instance, I've made a test at the Controller Class:

@RequestMapping(value = "/soap", method = RequestMethod.GET)
public String testeSoap() {
    ProcuraPMPorREClient pm = new ProcuraPMPorREClient();
    ProcuraPMPorREResponse response = pm.getPMPorRE(123456); 
    System.out.println(response.getProcuraPMPorREResult().getNomePM());
  return null;
}

在这种情况下,网络服务不工作,系统显示此错误消息:java.lang.IllegalStateException: 未注册编组器.检查 WebServiceTemplate 的配置.我不知道为什么,但 web 服务在一个特定的地方工作而在另一个地方不起作用.如果有人知道发生了什么,我很感激!谢谢!

In this case, the webservice doesn't work and the system show this error message: java.lang.IllegalStateException: No marshaller registered. Check configuration of WebServiceTemplate. I don't know why, but the webservice works in a specific place and doesn't work in the other. If someone knows what happen, I apreciate! Thanks!

推荐答案

在这种情况下,我无法像我所做的那样在控制器中实例化一个新对象:

In this case I cant instanciate a new object in the Controller like i've done:

ProcuraPMPorREClient pm = new ProcuraPMPorREClient();

而不是这个,我需要创建一个@Autowired 对象,如下所示:

Instead of this, I need to create a @Autowired object, like this:

@Autowired ProcuraPMPorREClient pm;

之后,我只调用相同的例程:

After, I only call the same routines:

ProcuraPMPorREResponse response = pm.getPMPorRE(123456); 
System.out.println(response.getProcuraPMPorREResult().getNomePM());

这工作得很好.

这篇关于使用 SOAP Web 服务错误(未注册编组器.检查 WebServiceTemplate 的配置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆