问题描述
我有这个示例代码:
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
但我知道该方法存在...有什么问题?
but i know that the method exists... whats wrong?
推荐答案
如果仍有问题,请也发布 WSDL.
Please post the WSDL too if you still have problems.
1) Web 服务调用失败,因为它找不到名为 getVServers
且命名空间为 {}
(空命名空间)的方法.
1) The web service invocation fails because it can't find a method called getVServers
with namespace {}
(empty namespace).
您的请求类似于:
<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
:
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>
为了添加命名空间,请更改创建 bodyName 的方式:
In order to add a namespace change the way you create bodyName:
QName bodyName = new QName("http://your-namespace-from-wsdl.com", "getVServers", "ns");
如果在您的 XML 架构上设置了 elementFormDefault="qualified"
或者 form="qualified"
存在于您的元素中.
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) 我认为您的 URL 端点不应包含 ?wsdl.
2) I think your URL endpoint should not contain ?wsdl.
3) 您正在尝试连接到 HTTPS 网络服务.请确保相应地设置您的证书和 DefaultSSLFactory.
3) You are trying to connect to a HTTPS webservice. Make sure you setup your certificates and DefaultSSLFactory accordingly.
这篇关于客户端找不到 {} 的调度方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!