简体   繁体   中英

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

I have created one SOAP Application to connect to QuickBooks Desktop via QuickBooksWebConnector. I have given my wsdl url to WebConnector. While calling 1st callback of authentication, connector shows me this error :

QBWC1012: Authentication failed due to following error message. Object reference not set to an instance of an object. See QWCLog for more details. Remember to turn logging on.

Which ideally means : Object reference not set to an instance of an object.

When I am trying to execute this from SOAPUI or WebServiceExplorer, it shows correct response message as given below :

Request :

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

Response :

<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>

(Taken from WebServiceExplorer) As I have searched for this error : It may cause when connector gets something null or invalid in response causes this error. How to solve this kind of error.

I am new to SOAP Webservice and also new with QuickBooks.

Thanks in advance.

Worked Solution :

I added annotation in method declaration and model class definitions to solve this kind of errors.(shown below)

Annotations for Service Declaration :

@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    
}

Annotation for Model Classes :

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;
    }

}

For more detail about what to write in these annotations[targetNamespace / webAction / XmlType] you can refer this link :

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

I'm using Node via node-soap, and the issue I had with this error was that I was sending authenticationResult instead of authenticateResult. Here is the output XML that worked (not setting an xml style in the QWC so basicall):

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM