【问题标题】:Client Cannot find dispatch method for {}客户端找不到 {} 的调度方法
【发布时间】:2023-04-07 19:01:01
【问题描述】:

我有这个示例代码:

    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:Client 找不到 {}getVServers

的调度方法

但我知道该方法存在...有什么问题?

【问题讨论】:

标签: java web-services soap wsdl


【解决方案1】:

如果您仍有问题,请也发布 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 架构上设置了 elementFormDefault="qualified" 或者如果您的元素上存在 form="qualified",则可能还需要添加 loginNamepassword 前缀。

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

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

【讨论】:

    猜你喜欢
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    相关资源
    最近更新 更多