在Java中使用自动任务API查询帐户
我一直试图使用Java的自动任务API,但没有成功。我构建的SOAP消息如下所示:在Java中使用自动任务API查询帐户,java,soap,Java,Soap,我一直试图使用Java的自动任务API,但没有成功。我构建的SOAP消息如下所示: SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); soapEnvelope.addNamespaceDeclaration("atns", AUTOTA
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
methodElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);
这将返回一个
ATWSError
。我做错了什么?您缺少sXML
元素:
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
SOAPElement sxmlElement = methodElement.addChildElement("sXML", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
sxmlElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);
这应该行。您缺少
sXML
元素:
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
SOAPElement sxmlElement = methodElement.addChildElement("sXML", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
sxmlElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);
这应该行得通