Web Services 使用marshalSendAndReceive时,调用SOAP服务返回500错误

mznpcxlj  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(214)

我使用的是Sping Boot 和Java 11。
我正在尝试编写一个SOP客户端来调用下面的Web服务。服务提供商已经提供了一个工具来测试它,从这里你可以看到它正在按预期工作。

结果-返回200:

我使用提供的WSDL成功生成存根,然后使用生成的ObjectFactory编写下面的Java客户端:

String PROCON_SOAP_ACCESS_URL = "http://********/ProCONWS/WebService_PCSOrderEntry.asmx";

public CalculateMD5Response calculateMD5(final String userName) {
    String msg = null;
    String parameters = null;
    try {
        // request
        ObjectFactory objectFactory = new ObjectFactory();
        CalculateMD5 request = objectFactory.createCalculateMD5();
        request.setUser("pcscord");
        request.setTimestamp(DateUtil.dateToString(new Date(), "yyyyMMdd HHmmss"));
        request.setSecretWord("********");
        parameters = URLEncoder.encode("user="+request.getUser()+"&timestamp="+request.getTimestamp()+"&Secret_word="+request.getSecretWord(), "UTF-8");

        PROCON_SOAP_ACCESS_URL = PROCON_SOAP_ACCESS_URL + "/calculate_MD5";//?"+parameters;

        // call the SOAP service
        logger.info("About to call Procon SOAP Service: " + PROCON_SOAP_ACCESS_URL + ".");
        JAXBElement<String> jaxbElementPayload = objectFactory.createString(parameters);
        Object response = getWebServiceTemplate().marshalSendAndReceive(PROCON_SOAP_ACCESS_URL, jaxbElementPayload);
        logger.info("Called Procon SOAP service. Response: " + response);
    } catch (Exception e) {
        msg = "FAILURE: There was an error calling the Procon SOAP service. Exception: "+e.getMessage()+". URL: "+PROCON_SOAP_ACCESS_URL+" and PARAMETERS: "+parameters+".";
        logger.error(msg);
    }
    return null;
}

但是,这将返回500错误:

Internal Server Error [500]

据我所知,getWebServiceTemplate().marshalSendAndReceive应该使用给定的URL和负载执行SOAPPOST请求。
我是否使用了错误的生成存根?URLEncoder.encode是否错误地格式化了有效负载?如有任何反馈,敬请谅解。

camsedfj

camsedfj1#

检查元素的名称。可以添加@XmlRootElement("<ElementName>")

相关问题