Java 中的对象引用未设置为 SOAP WebService 的对象实例

Object reference not set to an instance of an object for SOAP WebService in Java

我已经创建了一个 SOAP 应用程序以通过 QuickBooksWebConnector 连接到 QuickBooks 桌面。我已将我的 wsdl url 提供给 WebConnector。在调用第一个身份验证回调时,连接器向我显示此错误:

QBWC1012:由于以下错误消息,身份验证失败。 对象引用未设置为对象的实例。有关详细信息,请参阅 QWCLog。记得开启登录。

这在理想情况下意味着:未将对象引用设置为对象的实例。

当我尝试从 SOAPUI 或 WebServiceExplorer 执行此操作时,它显示正确的响应消息,如下所示:

要求:

<soapenv:Envelope>
  <soapenv:Body>
    <q0:authenticate>
      <q0:strUserName>Admin</q0:strUserName>
      <q0:strPassword>Admin</q0:strPassword>
   </q0:authenticate>
  </soapenv:Body>
</soapenv:Envelope>

回复:

<soapenv:Envelope>
  <soapenv:Body>
    <authenticateResponse>
      <authenticateReturn xsi:type="ns1:ArrayOfString">
        <ns1:string>{57F3B9B1-86F1-4fcc-B1EE-566DE1813D20}</ns1:string>
        <ns1:string>none</ns1:string>
      </authenticateReturn>
    </authenticateResponse>
  </soapenv:Body>
</soapenv:Envelope>

(取自WebServiceExplorer) 当我搜索此错误时:它可能会导致当连接器在响应中获取空值或无效内容时导致此错误。 怎么解决这种错误。

我是 SOAP Webservice 的新手,也是 QuickBooks 的新手。

提前致谢。

有效的解决方案:

我在方法声明和模型class定义中添加了注释来解决这种错误。(如下所示)

服务声明注释:

@WebService(name = "QBWebConnectorSvcSoap", targetNamespace = "http://developer.intuit.com/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface QBWebConnectorSvcSoap {

@WebMethod(action = "http://developer.intuit.com/authenticate")
    @WebResult(name = "authenticateResult", targetNamespace = "http://developer.intuit.com/")
    @RequestWrapper(localName = "authenticate", targetNamespace = "http://developer.intuit.com/", className = "com.cantero.quickbooks.ws.Authenticate")
    @ResponseWrapper(localName = "authenticateResponse", targetNamespace = "http://developer.intuit.com/", className = "com.cantero.quickbooks.ws.AuthenticateResponse")
    public ArrayOfString authenticate(
        @WebParam(name = "strUserName", targetNamespace = "http://developer.intuit.com/")
        String strUserName,
        @WebParam(name = "strPassword", targetNamespace = "http://developer.intuit.com/")
        String strPassword);

//same for remaining methods    
}

模型注释 类 :

package com.cantero.quickbooks.ws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
 * <p>Java class for anonymous complex type.
 * <p>The following schema fragment specifies the expected content contained within this class.
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="strUserName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="strPassword" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "strUserName",
    "strPassword"
})
@XmlRootElement(name = "authenticate")
public class Authenticate {

    protected String strUserName;
    protected String strPassword;

    public String getStrUserName() {
        return strUserName;
    }

    public void setStrUserName(String value) {
        this.strUserName = value;
    }

    public String getStrPassword() {
        return strPassword;
    }

    public void setStrPassword(String value) {
        this.strPassword = value;
    }

}

关于在这些注解[targetNamespace / webAction / XmlType]中写什么的更多细节,你可以参考这个link:

https://www.connexforquickbooks.com/qbwebservice.asmx?op=authenticate

我正在通过 node-soap 使用 Node,这个错误的问题是我发送的是 authenticationResult 而不是 authenticateResult。这是有效的输出 XML(未在 QWC 中设置 xml 样式,所以基本):

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://developer.intuit.com/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
  <soap:Body>
    <authenticateResponse xmlns="http://developer.intuit.com/">
      <authenticateResult>
        <string>12345678</string>
        <string></string>
      </authenticateResult>
    </authenticateResponse>
  </soap:Body>
</soap:Envelope>