Java SOAP请求未调用正确的方法
我正在做一个针对这个的soap请求 为此,我生成了一个有效的soap信封,该信封使用该实用程序请求正确的数据 但是当我像这样从java请求它时Java SOAP请求未调用正确的方法,java,web-services,soap,wsdl,Java,Web Services,Soap,Wsdl,我正在做一个针对这个的soap请求 为此,我生成了一个有效的soap信封,该信封使用该实用程序请求正确的数据 但是当我像这样从java请求它时 SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection();
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类等等。。。仍然无法让它工作。有什么想法吗
编辑
如果有人遇到类似的问题,那么下面是添加证书的命令。可以从google轻松找到InstallCert.java
java InstallCert[主机]:[端口]
keytool-exportcert-alias[host\u from\u installcert\u output]-密钥库jssecacerts-storepass[“changeit”是默认值]-文件[host].cer
keytool-importcert-alias[host]-keystore[path to system keystore]-storepass[your_keystore\u password]-file[host].cer如果还没有,请重试
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>";
}
publicstaticvoidmain(字符串[]args)抛出IOException、SOAPException{
SOAPConnectionFactory SOAPConnectionFactory=SOAPConnectionFactory
.newInstance();
SOAPConnection SOAPConnection=soapConnectionFactory
.createConnection();
字符串url=”http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl";
//当我把它换成这个的时候
// https://www.openxades.org:9443/DigiDocService 我收到一封邮件
//失败,并显示不同的错误代码。
MessageFactory MessageFactory=MessageFactory.newInstance();
InputStream is=new ByteArrayInputStream(getXmlString().getBytes());
SOAPMessage SOAPMessage=messageFactory.createMessage(null,is);
SOAPPart SOAPPart=soapMessage.getSOAPPart();
字符串serverURI=”https://www.openxades.org:9443/DigiDocService";
//肥皂袋
SOAPEnvelope=soapPart.getEnvelope();
envelope.addNamespaceDeclaration(“,serverURI”);
MimeHeaders=soapMessage.getMimeHeaders();
headers.addHeader(“SOAPAction”,即“);
soapMessage.saveChanges();
SOAPMessage soapResponse=soapConnection.call(SOAPMessage,serverURI);
ByteArrayOutputStream out=新建ByteArrayOutputStream();
soapResponse.writeTo(out);
String strMsg=新字符串(out.toByteArray());
系统输出打印LN(strMsg);
}
静态字符串getXmlString(){
返回“”
+ ""
+ ""
+ " "
+ "?"
+ ""
+ ""
+ "";
}
当我更改它时,我得到消息发送失败和一些错误代码(谷歌不知道它们的意思)。例如错误代码10048或9548,但文本消息始终是消息发送失败。当我复制您提供的代码时,我仍然得到HttpSOAPConnection post严重:SAAJ0009:消息发送失败
现在开始工作,存在一些证书问题,SOAP请求是正确的。谢谢