WSDL 客户端调用失败

WSDL Client Calling Failed

第一次使用 SOAP 服务。我需要调用这个网络服务。 http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL

这是我使用 wsimport

生成的 11 个存根中的 2 个

我试了一整天,但我不断收到此错误消息。为什么?我怀疑是因为我没有正确通过身份验证 header。但与此同时,我想知道生成的存根为什么不附带 Authentication header 作为方法参数?那是正常的吗?需要帮忙。我很困惑。

Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Server was unable to process request. ---> Object reference not set to an instance of an object. Please see the server log to find more detail regarding exact cause of the failure.

WebLITETSServicesSoap.java

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

@WebService(name = "WebLITE_TSServicesSoap", targetNamespace = "TransactionalSubmissionsSvcs")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface WebLITETSServicesSoap {

    @WebMethod(operationName = "GetTemplateList", action = "TransactionalSubmissionsSvcs/GetTemplateList")
    @WebResult(name = "GetTemplateListResult", targetNamespace = "TransactionalSubmissionsSvcs")
    @RequestWrapper(localName = "GetTemplateList", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.GetTemplateList")
    @ResponseWrapper(localName = "GetTemplateListResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.GetTemplateListResponse")
    public String getTemplateList();


    @WebMethod(operationName = "SendWithXML", action = "TransactionalSubmissionsSvcs/SendWithXML")
    @WebResult(name = "SendWithXMLResult", targetNamespace = "TransactionalSubmissionsSvcs")
    @RequestWrapper(localName = "SendWithXML", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithXML")
    @ResponseWrapper(localName = "SendWithXMLResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithXMLResponse")
    public String sendWithXML(
        @WebParam(name = "xmldoc", targetNamespace = "TransactionalSubmissionsSvcs")
        SendWithXML.Xmldoc xmldoc);


    @WebMethod(operationName = "SendWithJSON", action = "TransactionalSubmissionsSvcs/SendWithJSON")
    @WebResult(name = "SendWithJSONResult", targetNamespace = "TransactionalSubmissionsSvcs")
    @RequestWrapper(localName = "SendWithJSON", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithJSON")
    @ResponseWrapper(localName = "SendWithJSONResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithJSONResponse")
    public String sendWithJSON(
        @WebParam(name = "emaillist", targetNamespace = "TransactionalSubmissionsSvcs")
        String emaillist,
        @WebParam(name = "params", targetNamespace = "TransactionalSubmissionsSvcs")
        String params);

}

WebLITETSServices.java

import javax.xml.namespace.QName;
import javax.xml.ws.*;
import java.net.MalformedURLException;
import java.net.URL;


@WebServiceClient(name = "WebLITE_TSServices", targetNamespace = "TransactionalSubmissionsSvcs", wsdlLocation = "http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL")
public class WebLITETSServices
    extends Service
{

    private final static URL WEBLITETSSERVICES_WSDL_LOCATION;
    private final static WebServiceException WEBLITETSSERVICES_EXCEPTION;
    private final static QName WEBLITETSSERVICES_QNAME = new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServices");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        WEBLITETSSERVICES_WSDL_LOCATION = url;
        WEBLITETSSERVICES_EXCEPTION = e;
    }

    public WebLITETSServices() {
        super(__getWsdlLocation(), WEBLITETSSERVICES_QNAME);
    }

    public WebLITETSServices(WebServiceFeature... features) {
        super(__getWsdlLocation(), WEBLITETSSERVICES_QNAME, features);
    }

    public WebLITETSServices(URL wsdlLocation) {
        super(wsdlLocation, WEBLITETSSERVICES_QNAME);
    }

    public WebLITETSServices(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, WEBLITETSSERVICES_QNAME, features);
    }

    public WebLITETSServices(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public WebLITETSServices(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    @WebEndpoint(name = "WebLITE_TSServicesSoap")
    public WebLITETSServicesSoap getWebLITETSServicesSoap() {
        return super.getPort(new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServicesSoap"), WebLITETSServicesSoap.class);
    }

    @WebEndpoint(name = "WebLITE_TSServicesSoap")
    public WebLITETSServicesSoap getWebLITETSServicesSoap(WebServiceFeature... features) {
        return super.getPort(new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServicesSoap"), WebLITETSServicesSoap.class, features);
    }

    private static URL __getWsdlLocation() {
        if (WEBLITETSSERVICES_EXCEPTION!= null) {
            throw WEBLITETSSERVICES_EXCEPTION;
        }
        return WEBLITETSSERVICES_WSDL_LOCATION;
    }

}

我试过了运行TestApplication

public class TestApplication {

    public static void main(String[] args) throws MalformedURLException {
        MailAdapterApplication adapterApplication = new MailAdapterApplication();
        adapterApplication.run();
    }

    public void run() throws MalformedURLException {

    WebLITETSServices services = new WebLITETSServices();
    WebLITETSServicesSoap servicesSoap = services.getPort(WebLITETSServicesSoap.class);
    Map<String, Object> req_ctx =((BindingProvider)servicesSoap).getRequestContext();
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Username",Collections.singletonList("sansun@weblite.com.my"));
    headers.put("Password", Collections.singletonList("P@ssW0rd32!"));
    headers.put("APIKey", Collections.singletonList("QdrLKxog"));

    req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
    System.out.println(servicesSoap.getTemplateList());

    }

}

Client received SOAP Fault from server: Server was unable to process request.
Object reference not set to an instance of an object.
I keep getting this error message. Why?

确实您确实调用了该服务,但是服务器 returned 了一个带有错误消息的错误代码,其中 returned 有效负载没有映射到任何预期的 return 类型或肥皂故障异常。您提供的文本中没有更多信息。

检查真正 returned 的响应状态代码和负载将非常有用。如何记录respone payload取决于你使用的webservice库(cxf, axis2, ??)

I suspect because i did not pass in the authentication header correctly.

你应该确认怀疑,从提供的信息中无法分辨。不过,如果您没有提供任何身份验证信息,则很有可能

But at the same time i'm wondering how come the generated stub does not comes with Authentication header as a method param? is that normal? Need help. I'm so confusing.

我假设在 "Authentication header" 下你指的是 AuthHeader header。您可能需要在调用 wsimport 时启用 header 生成,这取决于所使用的框架。从默认 JDK 使用 wsimport 时,尝试使用 -XadditionalHeaders 参数