java调用webservice接口

humulin 发布于 2014/10/28 17:51
阅读 4K+
收藏 1

最近做个项目,要用java调用webservice接口,写个测试类就报错了,求大神指点,以下是代码及错误信息:

try {
            String endpoint = "http://www.xdz.gov.cn:8080/system/services/UserService?wsdl";
            //直接引用远程的wsdl文件
            Service service = new Service();
           Call call = (Call)service.createCall();
           call.setTargetEndpointAddress(new URL(endpoint));
            call.setOperationName("userLogin");//WSDL里面描述的接口名称
            call.addParameter("servicesuserinfo", org.apache.axis.encoding.XMLType.XSD_STRING,
            javax.xml.rpc.ParameterMode.IN);//接口的参数
            call.addParameter("useraccount", org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);//接口的参数
            call.addParameter("password", org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);//接口的参数
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型  


            String result = (String)call.invoke(new Object[]{PwdCrypt.encrypt(encode),"admin",PwdCrypt.encrypt("!2@:?+)JUXDZ^%&*")});
            //给方法传递参数,并且调用方法
            System.out.println("result is "+result);
     }
     catch (Exception e) {
            e.printStackTrace();
     }
异常信息如下:

log4j:ERROR Could not find value for key log4j.appender.R
log4j:ERROR Could not instantiate appender named "R".
[QC] INFO [main] org.apache.axis.client.Call.invoke(1853) | Mapping Exception to AxisFault
     AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultString: java.lang.reflect.InvocationTargetException
 faultActor: null
 faultDetail: 
hostname: localhost.localdomain


java.lang.reflect.InvocationTargetException
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:135)
at org.apache.axis.encoding.DeserializationContextImpl.endElement(DeserializationContextImpl.java:942)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1789)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2965)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:232)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:546)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:377)
at org.apache.axis.client.Call.invokeEngine(Call.java:2132)
at org.apache.axis.client.Call.invoke(Call.java:2102)
at org.apache.axis.client.Call.invoke(Call.java:1851)
at org.apache.axis.client.Call.invoke(Call.java:1777)
at org.apache.axis.client.Call.invoke(Call.java:1315)
at com.hz.sunday.gaoxinfccrm.utils.HttpRequestUtil.main(HttpRequestUtil.java:116)

加载中
0
南湖船老大
南湖船老大

楼主先用soapUI试试,看看是你的问题还是他的问题

0
humulin
humulin

引用来自“南湖船老大”的评论

楼主先用soapUI试试,看看是你的问题还是他的问题

试过了,返回了这么一串东西,应该是那边的问题

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Server.userException</faultcode>
         <faultstring>java.lang.reflect.InvocationTargetException</faultstring>
         <detail>
            <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">localhost.localdomain</ns1:hostname>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

返回顶部
顶部