Client Cannot find dispatch method for {}

China☆狼群 提交于 2019-12-24 13:52:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14710917/client-cannot-find-dispatch-method-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!