SOAP 请求未调用正确的方法
SOAP request does not call correct method
我正在针对此提出 soap 请求https://www.openxades.org:8443/?wsdl
为此我生成了一个有效的肥皂信封可以看到here and this envelope requests correct data with this utility http://soapclient.com/SoapMsg.html
但是当我像这样从java请求它时
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(req.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, url);
我得到的是通用 wsdl 文件,而不是方法调用。我已经尝试了不同的 URL 组合,从 wsdl 文件生成 java 类 等等......仍然无法让它工作。有什么想法吗?
编辑
如果有人遇到类似问题,那么这些就是添加证书的命令。 InstallCert.java 可以很容易地从 google.
中找到
java InstallCert [主机]:[端口]
keytool -exportcert -alias [host_from_installcert_output] -keystore jssecacerts -storepass ["changeit" is default] -file [host].cer
keytool -importcert -alias [host] -keystore [系统密钥库的路径] -storepass [your_keystore_password] -file [host].cer
如果你还没有,试试
SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);
而不是
SOAPMessage soapResponse = soapConnection.call(soapMessage, url);
因为目前调用将转到此 WSDL 的 url。
确保你的 XML 是正确的。为了测试,我刚刚向 return some 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>";
}
我正在针对此提出 soap 请求https://www.openxades.org:8443/?wsdl
为此我生成了一个有效的肥皂信封可以看到here and this envelope requests correct data with this utility http://soapclient.com/SoapMsg.html
但是当我像这样从java请求它时
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(req.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, url);
我得到的是通用 wsdl 文件,而不是方法调用。我已经尝试了不同的 URL 组合,从 wsdl 文件生成 java 类 等等......仍然无法让它工作。有什么想法吗?
编辑
如果有人遇到类似问题,那么这些就是添加证书的命令。 InstallCert.java 可以很容易地从 google.
中找到java InstallCert [主机]:[端口]
keytool -exportcert -alias [host_from_installcert_output] -keystore jssecacerts -storepass ["changeit" is default] -file [host].cer
keytool -importcert -alias [host] -keystore [系统密钥库的路径] -storepass [your_keystore_password] -file [host].cer
如果你还没有,试试
SOAPMessage soapResponse = soapConnection.call(soapMessage, serverURI);
而不是
SOAPMessage soapResponse = soapConnection.call(soapMessage, url);
因为目前调用将转到此 WSDL 的 url。
确保你的 XML 是正确的。为了测试,我刚刚向 return some 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>";
}