迷彩风情的gravatar头像
迷彩风情 2015-10-28 18:52:58

Android开发中调用Spring CXF整合发布的java WebService接口为什么抛出异常错误?

2015-10-28 18:50:39 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
警告: Interceptor for {http://service.qdexam.com/}HelloServiceImplService#{http://service.qdexam.com/}say has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"http://service.qdexam.com/", local:"name"). Expected elements are <{}name> 
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:882)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:703)
    at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:160)
    at org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:108)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:243)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"http://service.qdexam.com/", local:"name"). Expected elements are <{}name>]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:843)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:102)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder$2.run(JAXBEncoderDecoder.java:871)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:869)
    ... 26 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://service.qdexam.com/", local:"name"). Expected elements are <{}name>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:101)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:243)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
    ... 32 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://service.qdexam.com/", local:"name"). Expected elements are <{}name>
    ... 43 more

 

wsdl文件是这样的:

Android开发中调用Spring CXF整合发布的java WebService接口为什么抛出异常错误?

 

 

android调用代码如下:

//WSDL文档中的命名空间
    private static final String nameSpace3="http://myUseIos/";
    
    //WSDL文档中的URL
    private static final String WSDL3="http://192.168.1.103:8080/qdksptCxfService/ksptService?wdsl";
       
    //�?��调用的方法名(获得本天气预报Web Services支持的洲、国内外省份和城市信�?
    private static final String studentLogin="studentLogin";
	
	public void studentLogin() {
        SoapObject soapObject=new SoapObject(nameSpace3,studentLogin);
        //request.addProperty("参数", "参数�?);调用的方法参数与参数值(根据具体�?��可�?可不选)
        soapObject.addProperty("usreName", "7777777776");
    	soapObject.addProperty("password", "7777777776");
        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(soapObject);//envelope.bodyOut=request;
        //AndroidHttpTransport httpTranstation=new AndroidHttpTransport(WSDL3);
        HttpTransportSE httpTranstation=new HttpTransportSE(WSDL3);
        try {
            httpTranstation.call(nameSpace3+studentLogin, envelope);
            Object object = envelope.getResponse();
            //下面对结果进行解析,结构类似json对象
            System.out.println(object.toString()+"+++++++++++++++++++++++++++");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } 
	}
所有回答列表(3)
迷彩风情的gravatar头像
迷彩风情  LV26 2015年10月29日

正确的android调用代码如下

String nameSpace3="http://myUseIos/";
    
    String WSDL3="http://192.168.1.103:8080/qdksptCxfService/ksptService";
       
    String studentLogin="studentLogin";
    
    String listPapers = "listPapers";
    
    String listPapersCurrent = "listPapersCurrent";
    
    // 登录
    public void studentLogin() {
    	HttpTransportSE httpTranstation=new HttpTransportSE(WSDL3);
    	SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
    	SoapObject request =new SoapObject(nameSpace3,studentLogin);
    	String userName = "7777777777";
    	String password = "7777777777";
    	request.addProperty("userName", userName);
    	request.addProperty("password", password);
    	envelope.setOutputSoapObject(request);
    	try {
    		httpTranstation.call(null, envelope);
    		Object object = envelope.getResponse();
    		System.out.println("object" + object);  
    	} catch (IOException e) {
    		e.printStackTrace();
    	} catch (XmlPullParserException e) {
    		e.printStackTrace();
    	} 
    }
}
评论(0) 最佳答案
tudou的gravatar头像
tudou  LV7 2015年10月29日

[javax.xml.bind.UnmarshalException: unexpected element (uri:"http://service.qdexam.com/", local:"name"). Expected elements are <{}name>]

貌似是你的namespace2边没有对应上。

heroshen的gravatar头像
heroshen  LV7 2015年10月29日

之前貌似服务器端和客户端2者的方法没有对应上报过这种错误,检测一下2边的方法名以及参数名、参数类型什么的

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友