第一次使用SOAP服务。我需要调用此Web服务。 http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL
这是我使用 wsimport
生成的11个存根中的2个我一整天都在尝试,但是我不断收到此错误消息。为什么?我怀疑是因为我没有正确传递身份验证标头。但是同时,我想知道为什么生成的存根不带有身份验证标头作为方法参数?那正常吗?需要帮忙。我很困惑。
线程“主”中的异常 com.sun.xml.internal.ws.fault.ServerSOAPFaultException:客户端 从服务器收到SOAP错误:服务器无法处理请求。 --->对象引用未设置为对象的实例。请查看服务器日志以查找有关导致此问题的确切原因的更多详细信息 失败。
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());
}
}
答案 0 :(得分:1)
客户端从服务器接收到SOAP错误:服务器无法处理请求。
你调用的对象是空的。
我不断收到此错误消息。为什么?
确实您确实调用了该服务,但是服务器返回了一条带错误消息的错误代码,其中返回的有效负载没有映射到任何预期的返回类型或soap错误异常。您提供的文字中没有更多信息。
检查真正返回的响应状态代码和有效负载将非常有用。如何记录重做的有效负载取决于您使用的Web服务库(cxf,axis2,??)
我怀疑是因为我没有正确传递身份验证标头。
您应该从所提供的信息中确认怀疑,但无法判断。尽管如果您不提供任何身份验证信息,则很有可能
但是同时我想知道为什么生成的存根不带有身份验证标头作为方法参数?那正常吗?需要帮忙。我很困惑。
我假设在“身份验证标头”下,您指的是AuthHeader标头。调用 wsimport 时可能需要启用标头生成,这也取决于所使用的框架。从默认JDK使用wsimport时,请尝试使用-XadditionalHeaders
参数