Server did not recognize the value of HTTP Header SOAPAction 解决

当你在使用Java调用.net实现的webservice出现如标题的exception时,恰好你正在使用https://spring.io/guides/gs/consuming-web-service/ 进行soap对接,不要慌。我刚踩过这个坑。

经过查找之后发现JAX-WS规范不需要SoapAction,但是.NET需要,所以产生了这个错误。

解决办法:

首先获取wsdl:

 Server did not recognize the value of HTTP Header SOAPAction 解决_第1张图片

然后引入dependency


    org.springframework.ws
    spring-ws-core

引入plugin


    org.jvnet.jaxb2.maven2
    maven-jaxb2-plugin
    0.12.3
    
        
            
                generate
            
        
    
    
        WSDL
        com.xxx.givenchy.email
        
            
                
                    
                    ${basedir}/src/main/resources/schemas
                    
                    
                        *.wsdl
                    
                    
                    
                    
                    
                
                
            
        
    

配置web service

@Configuration
public class EmailClientConfig {

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // this package must match the package in the  specified in
        // pom.xml
        marshaller.setContextPath("com.xxx.givenchy.email");
        return marshaller;
    }

    @Bean
    public EmailClient emailClient(Jaxb2Marshaller marshaller) {
        EmailClient client = new EmailClient();
        client.setDefaultUri("http://w01app39.xxx.com/ServiceCenter/MailCenter.asmx");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        return client;
    }

封装调用方法:
public class EmailClient extends WebServiceGatewaySupport {

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

    public SendMailResponse sendEmail(SendMail request) {


        log.info("Requesting location for " + request);

        WebServiceTemplate template = getWebServiceTemplate();
        SendMailResponse response = (SendMailResponse) template
                .marshalSendAndReceive(request,
                        new SoapActionCallback(
                                "http://service.xxx.sh.cn/sendMail"));

        return response;
    }
}

注意加红部分,是导致异常的原因。这个action url从哪里来的呢?

看生成wsdl的链接。

Server did not recognize the value of HTTP Header SOAPAction 解决_第2张图片

保证action 和红框一致即可。

你可能感兴趣的:(Java)