Web Services 对象引用未设置为Java中SOAP WebService的对象示例

zsbz8rwp  于 2022-11-15  发布在  Java
关注(0)|答案(2)|浏览(197)

我已经创建了一个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 Web服务的新手,也是QuickBooks的新手。
先谢谢你。

oiopk7p5

oiopk7p51#

工作溶液:
我在方法声明和模型类定义中添加了annotation来解决这类错误。(如下所示)
服务声明的注解:

@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

ve7v8dk2

ve7v8dk22#

我正在通过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>

相关问题