最近根據wsdl文件生成客戶端代碼,使用MyEclipse的xfire和axis插件都報錯,報錯如截圖;
后來在網上搜,原因應該是服務端發布的時候使用的是axis1.2版本的,使用的版本過低.于是從網上下載了axis1.2的版本,再試,還是一樣報錯.
報錯信息如下:
<Recharge xmlns="ocs/server">
<in0 xmlns="">
<requestId>20090728000022</requestId>
<requestTime>20081102000000</requestTime>
<destinationId>13340011829</destinationId>
<destinationAttr>2</destinationAttr>
<balanceType>2000</balanceType>
<rechargeUnit>0</rechargeUnit>
<objType>5BC</objType>
<rechargeAmount>10</rechargeAmount>
<requestAmount>1</requestAmount>
<cardNumber/>
<channelID/>
<operSystem/>
</in0>
</Recharge>
java.lang.NullPointerException
at com.ctc.wstx.sw.BaseNsStreamWriter.doWriteDefaultNs(BaseNsStreamWriter.java:528)
at com.ctc.wstx.sw.SimpleNsStreamWriter.writeDefaultNamespace(SimpleNsStreamWriter.java:111)
at com.ctc.wstx.sw.SimpleNsStreamWriter.writeNamespace(SimpleNsStreamWriter.java:119)
at org.apache.axiom.om.impl.MTOMXMLStreamWriter.writeNamespace(MTOMXMLStreamWriter.java:146)
at org.apache.axiom.om.impl.serialize.StreamingOMSerializer.serializeElement(StreamingOMSerializer.java:243)
at org.apache.axiom.om.impl.serialize.StreamingOMSerializer.serializeNode(StreamingOMSerializer.java:76)
at org.apache.axiom.om.impl.serialize.StreamingOMSerializer.serialize(StreamingOMSerializer.java:59)
at org.apache.axiom.om.impl.util.OMSerializerUtil.serializeByPullStream(OMSerializerUtil.java:473)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:823)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:848)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:819)
at org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:180)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:848)
at org.apache.axiom.om.impl.llom.OMNodeImpl.serializeAndConsume(OMNodeImpl.java:419)
at org.apache.axis2.transport.http.SOAPOverHTTPSender$AxisSOAPRequestEntity.handleOMOutput(SOAPOverHTTPSender.java:190)
at org.apache.axis2.transport.http.SOAPOverHTTPSender$AxisSOAPRequestEntity.writeRequest(SOAPOverHTTPSender.java:232)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:541)
at org.apache.axis2.transport.http.SOAPOverHTTPSender.send(SOAPOverHTTPSender.java:119)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:335)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:204)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:674)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:237)
at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:202)
at com.huawei.bus.ws.ct.skeleton.UvcSoapForOcsServiceStub.Recharge(UvcSoapForOcsServiceStub.java:266)
at test.Test.main(Test.java:56)
把報錯的測試工程發到同事那里測試,一切正常.
最后只好從同事那里發過來axis的jar包導入,最后正常.
懷疑是axis版本不一樣,用比較工具比較兩個lib文件夾,果然axis的版本不一樣.
用org.apache.axis2.Version.getVersionText() 返回版本號,一個是1.1,一個是1.1.1(才發現axis2的2不是版本號...).
之前一直都用xfire,好像沒有遇到過服務端和客戶端版本不一致還會有問題.看來還是要慎用axis.