java 访问webservice 异常

问题描述

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

解决方案

我这里遇到的造成错误的原因是:
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’后缀。

解决方案二:
webservice的local name 是否正确

解决方案三:
和2楼同样的错误,正解,赞一个

时间: 2024-12-29 06:53:42

java 访问webservice 异常的相关文章

Java访问WebService返回XML数据的方法

  本文实例讲述了Java访问WebService返回XML数据的方法.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

Java访问WebService返回XML数据的方法_java

本文实例讲述了Java访问WebService返回XML数据的方法.分享给大家供大家参考.具体如下: import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.io.FileNotFoundException; import java.io

webservice-java 访问webService 怎么做windows 域验证

问题描述 java 访问webService 怎么做windows 域验证 地址大概是这个样子的,http://erp3.domain.ext:8000/sap/bc/srt/wsdl/bndg_54A6EE6788AE005DE10080000AB450B9/wsdl11/allinone/ws_policy/document?sap-client=800 浏览器访问的时候 现在需要在java中来做,读取数据存到数据库 解决方案 http://bbs.csdn.net/topics/39020

android ksoap2 访问webservice,连续两次调用时,第二次调用异常(转)

1.  代码如下 复制代码 Webservice.GetVcardByUserNo(String userId,String userNo); 这个是封装了的webservice接口. 2.在程序中连续两次调用该接口时,ksoap2在解析第二次调用返回的结果时抛异常.     异常信息如下:  代码如下 复制代码 org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in ja

java cxf webservice 传输文件异常

问题描述 java cxf webservice 传输文件异常 利用cxf传输大文件会报如下异常,请高手帮忙: [org.apache.cxf.phase.PhaseInterceptorChain]Interceptor for {http://impl.ws.zr.com/}zfFileService#{http://service.ws.zr.com/}getWsUser has thrown exception, unwinding now org.apache.cxf.intercep

服务器-ksoap访问webservice出现SocketException

问题描述 ksoap访问webservice出现SocketException ksoap访问服务器一个接口会随机出现java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)只有这个接口访问会随机出现异常其他的接口都能正常访问.服务器php写的webservice.....求大神解答 困扰好几天的问题

JAVA中的异常与错误处理详解

  异常与错误: 异常: 在Java中程序的错误主要是语法错误和语义错误,一个程序在编译和运行时出现的错误我们统一称之为异常,它是VM(虚拟机)通知你的一种方式,通过这种方式,VM让你知道,你(开发人员)已经犯了个错误,现在有一个机会来修改它.Java中使用异常类来表示异常,不同的异常类代表了不同的异常.但是在Java中所有的异常都有一个基类,叫做Exception. 错误: 它指的是一个合理的应用程序不能截获的严重的问题.大多数都是反常的情况.错误是VM的一个故障(虽然它可以是任何系统级的服务

java-安装Loadrunner后,本地工程访问出现异常

问题描述 安装Loadrunner后,本地工程访问出现异常 如题,访问本地发布的工程时,背景图都无法展示,用其他机器访问我本地服务也是一样效果,我访问其他机器服务也是一样,卸载后也咩有恢复正常,浏览器升级后也不行,换个浏览器也是一样效果 解决方案 使用此软件,访问JAVA工程不合理,应导入一个包,试一试

.net-.NET调JAVA的webservice接口报错是怎么回事?

问题描述 .NET调JAVA的webservice接口报错是怎么回事? webservice可访问,已访问到接口方法,参数和返回值都是string类型的.就是最后执行该方法时报错"Fault occurred while processing". 无论静态添加web引用或服务引用,还是代码动态添加,都是一样的错.动态调用是在最后invoke时报错.是怎么回事?怎么改?求大神帮忙~~