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();
    }
    }

webservice的local name 是否正确

我这里遇到的造成错误的原因是:
IWebServiceForMSPStub stub = new IWebServiceForMSPStub("http://local/axis/services/IWebServiceForMSP?wsdl");
ReqSearchCustomInfo request = new ReqSearchCustomInfo();
request.setSearchCID("gd");
System.out.println(stub.reqSearchCustomInfo("gd----",null));
对于xfire与axis2调用传入的wsdl的路径问题,要去掉‘?wsdl’后缀.
你可以参照axis2生成的代码,它调用的wsdl路径是没有‘?wsdl’后缀。