![](/img/trans.png)
[英](JAVA) SOAP WebService error object reference not set to an instance of an object
[英]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)当我搜索此错误时:它可能会导致连接器在响应中获取 null 或无效内容时导致此错误。 如何解决这种错误。
我是 SOAP Webservice 的新手,也是 QuickBooks 的新手。
提前致谢。
可行的解决方案:
我在方法声明和模型类定义中添加了注释 ,以解决此类错误。(如下所示)
服务声明批注:
@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>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="strUserName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="strPassword" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </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
我通过 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.