liuzc120 2015-01-09 06:23 采纳率: 0%
浏览 8456

java 访问webservice 异常

log4j:WARN No appenders could be found for logger (org.apache.axis2.context.AbstractContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.apache.axis2.AxisFault: First Element must contain the local name, Envelope , but found definitions
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
at ServiceQQ.getResult(ServiceQQ.java:25)
at ServiceQQ.main(ServiceQQ.java:59)
Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found definitions
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:299)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:246)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:228)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:198)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.internalCreateStAXSOAPModelBuilder(AbstractOMMetaFactory.java:119)
at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:129)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:426)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:405)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:55)
at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:179)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
... 9 more
访问代码: 不加访问验证的时候访问其他webservice正常
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
// http://hi.baidu.com/e_ville/blog/item/f6529fa1a6616a8e471064a3.html
/**

  • 测试WebService
  • @author
  • @history 2008-4-16
    */
    public class ServiceQQ{
    private static EndpointReference targetEPR = new EndpointReference(WebServiceC.url);

    public void getResult()throws Exception{
    ServiceClient sender = new ServiceClient();
    sender.setOptions(buildOptions());
    OMElement result = sender.sendReceive(buildParam());
    System.out.println(result);
    }
    private static OMElement buildParam() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("urn:sap-com:document:sap:rfc:functions", "");
    OMElement data = fac.createOMElement("ZTP_PROJECT", omNs);
    // OMElement inner = fac.createOMElement("byString", omNs);
    // inner.setText("1528");
    // data.addChild(inner);

    return data;
    

    }

    private static Options buildOptions() {
    HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
    basicAuth.setUsername(WebServiceC.userName);
    basicAuth.setPassword(WebServiceC.password);
    Options options = new Options();
    options.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
    options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    options.setAction("");
    options.setTo(targetEPR);

    //options.setProperty(propertyKey, property)
    
    // enabling MTOM in the client side
    // options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
    return options;
    

    }
    public static void main(String[] args) throws Exception {
    ServiceQQ s = new ServiceQQ();
    s.getResult();
    }
    }

  • 写回答

2条回答 默认 最新

  • oyljerry 2015-01-10 15:02
    关注

    webservice的local name 是否正确

    评论

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统