客户端找不到{}的调度方法

时间:2013-02-05 15:23:58

标签: java web-services soap wsdl

我有这个示例代码:

    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());
        }
    }

我收到了这个错误:

  

1)S:客户端找不到{} getVServers

的调度方法

但我知道该方法存在......什么是错的?

1 个答案:

答案 0 :(得分:5)

如果仍有问题,请发布WSDL。

1)Web服务调用失败,因为它无法找到名为getVServers且名称空间为{}的方法(空命名空间)。

您的请求类似于:

<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在默认命名空间中。它应该是这样的,其名称空间应该是来自WSDL定义的targetNamespace

<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>

为了添加命名空间,请按照创建bodyName的方式进行更改:

QName bodyName = new QName("http://your-namespace-from-wsdl.com", "getVServers", "ns");

如果在您的XML架构上设置loginName或者元素上存在password,则elementFormDefault="qualified"form="qualified"可能需要加前缀。

2)我认为您的URL端点不应包含?wsdl。

3)您正在尝试连接到HTTPS Web服务。确保相应地设置证书和DefaultSSLFactory。