我使用以下WSDL中的Apache CXF 2.x在eclipse中创建了一个Web服务客户端:
https://test.timbrado.com.mx/cfdi/wstimbrado.asmx?WSDL
在进行Web服务调用时,我得到以下错误堆栈跟踪(服务器无法处理请求--->引用未建立为对象实例的对象):
javax.xml.ws.soap.SOAPFaultException: El servidor no puede procesar la solicitud. ---> Referencia a objeto no establecida como instancia de un objeto.
[java] at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
[java] at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
[java] at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
[java] at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
[java] at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
[java] at $Proxy34.generaTimbre(Unknown Source)
[java] at com.vital.fevital.funciones.FacturaElectronica.timbrarWebService(FacturaElectronica.java:1258)
[java] at facturaVital.factura.servlet.FacturaVenta.generaFactura(FacturaVenta.java:1128)
[java] at facturaVital.factura.servlet.FacturaVenta.doPost(FacturaVenta.java:127)
[java] at facturaVital.factura.servlet.FacturaVenta.doGet(FacturaVenta.java:86)
[java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
[java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
[java] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
[java] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
[java] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
[java] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
[java] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
[java] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
[java] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
[java] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
[java] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
[java] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
[java] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
[java] at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
[java] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[java] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[java] at java.lang.Thread.run(Unknown Source)
我正在这样做的电话:
ObjectFactory of = new ObjectFactory();
AuthenticationHeader ah = of.createAuthenticationHeader();
ah.setUserName(cfdi.getUsuarioPAC());
ah.setPassword(cfdi.getPasswordPAC());
JAXBElement<AuthenticationHeader> jah = of.createAuthenticationHeader(ah);
ServicioTimbradoPruebas stp = new ServicioTimbradoPruebas();
ServicioTimbradoPruebasSoap stpSoap = stp.getServicioTimbradoPruebasSoap();
try{
WSBindingProvider bp = (WSBindingProvider)stpSoap;
Header hdr = Headers.create((JAXBRIContext) JAXBContext.newInstance(AuthenticationHeader.class),jah);
bp.setOutboundHeaders(hdr);
}catch(Exception ex){
ex.printStackTrace();
error = "Error en webservice ";
}
byte [] xmlBytes = cfdi.getXml().getBytes("UTF-8");
String result = stpSoap.generaTimbre(xmlBytes);
我在以下行中得到错误:
String result = stpSoap.generaTimbre(xmlBytes);
在我能够进行Web服务调用之前,但现在我无法执行此操作并且出现以下错误。有关如何解决这个问题的任何建议吗?
答案 0 :(得分:3)
我想这不是一个很好的答案,但无论如何:
该服务非常严重f * * up。
例如
<cfdi:xmlBytes>cdi:246460475753</cfdi:xmlBytes>
在
<cfdi:GeneraTimbre>
根据WSDL合同,是可选的:
<s:element name="GeneraTimbre">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="xmlBytes" type="s:base64Binary"/>
</s:sequence>
</s:complexType>
</s:element>
(注意 minOccurs =“0”!) 然而,当您发送没有可选部分的消息时,您将获得一个soapfault:
<soap:Body>
<soap:Fault>
<faultcode>soap:MustUnderstand</faultcode>
<faultstring>No se entendió el encabezado SOAP Security.</faultstring>
</soap:Fault>
</soap:Body>
正如我在开始时所说,这不是一个很好的答案,只是一个建议可能:尽量远离如此糟糕的书面服务。 (我的猜测是他们试图实施ws-sec,但是没有ws-policy框架,哪些可以完成,但是对于服务使用者来说几乎没有任何帮助如何正确使用它