Reputation: 4117
I have this sample code:
private static final String endpoint = "https://www.***.**:443/WSEndUser?wsdl";
public static void main(String[] args) throws SOAPException {
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPHeader header = message.getSOAPHeader();
header.detachNode();
/*
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
envelope.setAttribute("namespace","namespaceUrl");
*/
SOAPBody body = message.getSOAPBody();
QName bodyName = new QName("getVServers");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
SOAPElement symbol = bodyElement.addChildElement("loginName");
symbol.addTextNode("my login name");
symbol = bodyElement.addChildElement("password");
symbol.addTextNode("my password");
SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = connection.call(message, endpoint);
connection.close();
SOAPBody responseBody = response.getSOAPBody();
SOAPBodyElement responseElement = (SOAPBodyElement)responseBody.getChildElements().next();
SOAPElement returnElement = (SOAPElement)responseElement.getChildElements().next();
if(responseBody.getFault()!=null){
System.out.println("1) " + returnElement.getValue()+" "+responseBody.getFault().getFaultString());
} else {
System.out.println("2) " + returnElement.getValue());
}
}
and i got this error:
1) S:Client Cannot find dispatch method for {}getVServers
but i know that the method exists... whats wrong?
Upvotes: 2
Views: 28101
Reputation: 211
Please post the WSDL too if you still have problems.
1) The web service invocation fails because it can't find a method called getVServers
with namespace {}
(empty namespace).
Your request looks something like:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<getVServers>
<loginName>my login name</loginName>
<password>my password</password>
</getVServers>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
getVServers is on the default namespace. It should be something like this, where the namespace should be targetNamespace
from your WSDL definition:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns:getVServers xmlns:ns="http://your-namespace-from-wsdl.com">
<loginName>my login name</loginName>
<password>my password</password>
</ns:getVServers>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
In order to add a namespace change the way you create bodyName:
QName bodyName = new QName("http://your-namespace-from-wsdl.com", "getVServers", "ns");
Also loginName
and password
may need to be prefixed if elementFormDefault="qualified"
is set on your XML Schema or if form="qualified"
is present on your elements.
2) I think your URL endpoint should not contain ?wsdl.
3) You are trying to connect to a HTTPS webservice. Make sure you setup your certificates and DefaultSSLFactory accordingly.
Upvotes: 6