Reputation: 129
I was reading a lot of tutorials and similar questions on stackoverflow, but I still have a problem connecting to my SOAP service.
I am trying to call a SOAP web service using Java. I found a nice answer here: https://stackoverflow.com/a/15942217/2145530
The example works perfectly as is but when I change it to another wsdl file it no longer works:
public static void main(String args[]) throws Exception {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://192.168.200.165/soap/server.php";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "urn:BoardSOAP";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("soap", serverURI);
System.out.println(envelope.getNamespaceURI());
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "getBoardStatus");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
As you can see I changed those lines:
String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx";
String serverURI = "http://ws.cdyne.com/";
headers.addHeader("SOAPAction", serverURI + "ReturnCodes");
String url = "http://192.168.200.165/soap/server.php";
String serverURI = "urn:BoardSOAP";
headers.addHeader("SOAPAction", serverURI + "getBoardStatus");
Full output:
http://schemas.xmlsoap.org/soap/envelope/
Request SOAP Message:<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="urn:BoardSOAP"><SOAP-ENV:Header/><SOAP-ENV:Body/></SOAP-ENV:Envelope>
Response SOAP Message:<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Operation '' is not defined in the WSDL for this service</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
WSDL file isn't corrupted, I can communicate with it via SoupUI with no problem.
Upvotes: 1
Views: 2421
Reputation: 29
This way also worked for me:
saajSoapMessage.setSoapAction("urn:server#getBoardStatus");
Upvotes: -1
Reputation: 7406
In the answer you cite, the soapAction
for ReturnCodes
is http://ws.cdyne.com/ReturnCodes
, which is constructed by the line headers.addHeader("SOAPAction", serverURI + "ReturnCodes");
However, in your WSDL, since you are using not a URL but a URN for your namespace identifier, the soapAction
for getBoardStatus
is urn:server#getBoardStatus
. If you use the same concatenation scheme, you will be missing the #
and you will be using urn:BoardSoap
instead of urn:server
.
Try using `headers.Header("SOAPAction", "urn:server#getBoardStatus").
Upvotes: 3