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

时间:2017-12-29 06:17:16

标签: java web-services soap quickbooks

我创建了一个SOAP应用程序,通过QuickBooksWebConnector连接到QuickBooks Desktop。我已将我的wsdl网址提供给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) 因为我搜索了这个错误:它可能导致连接器获取null或响应无效导致此错误。 如何解决这种错误。

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

提前致谢。

1 个答案:

答案 0 :(得分:0)

工作解决方案:

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

服务声明注释:

@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]中写入内容的更多详细信息,请参阅此链接:

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