SOAP请求不会调用正确的方法

时间:2015-05-12 13:52:40

标签: java web-services soap wsdl

我正在针对此https://www.openxades.org:8443/?wsdl

执行肥皂请求

为此我可以看到生成有效的肥皂信封here,此信封使用此实用程序请求正确的数据http://soapclient.com/SoapMsg.html

但是当我从这样的请求它时

Expression

我得到通用的wsdl文件而不是方法调用。我尝试过不同的URL组合,从wsdl文件生成java类等等......仍然无法使其工作。有什么想法吗?

修改

如果有人应该来这里遇到类似的问题,那么这些是添加证书的命令。可以从谷歌轻松找到InstallCert.java。

java InstallCert [host]:[port]

keytool -exportcert -alias [host_from_installcert_output] -keystore jssecacerts -storepass [" changeit"是默认的] -file [host] .cer

keytool -importcert -alias [host] -keystore [系统密钥库的路径] -storepass [your_keystore_password] -file [host] .cer

1 个答案:

答案 0 :(得分:0)

如果您还没有,请尝试

SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);

而不是

SOAPMessage soapResponse = soapConnection.call(soapMessage, url);

因为此时调用将转到此WSDL的URL。

确保您的XML正确无误。为了测试,我刚刚添加了一个方法来返回一些XML。下面的示例代码可以使用。

public static void main(String[] args) throws IOException, SOAPException {

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
            .newInstance();
    SOAPConnection soapConnection = soapConnectionFactory
            .createConnection();

    String url = "http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl";
    // when I replace it with this
    // https://www.openxades.org:9443/DigiDocService I get message send
    // failed, and different error codes.

    MessageFactory messageFactory = MessageFactory.newInstance();
    InputStream is = new ByteArrayInputStream(getXmlString().getBytes());
    SOAPMessage soapMessage = messageFactory.createMessage(null, is);
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "https://www.openxades.org:9443/DigiDocService";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("", serverURI);
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", "");
    soapMessage.saveChanges();
    SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    soapResponse.writeTo(out);
    String strMsg = new String(out.toByteArray());

    System.out.println(strMsg);

}

static String getXmlString() {
    return "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
            + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""
            + " xmlns:dig=\"http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl\">"
            + "<soapenv:Header/>"
            + "<soapenv:Body>"
            + " <dig:CloseSession soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> "
            + "<Sesscode xsi:type=\"xsd:int\">?</Sesscode>"
            + "</dig:CloseSession>"
            + "</soapenv:Body>"
            + "</soapenv:Envelope>";

}