CXF调用WEBSERVICES时异常,折腾几天了,求高手帮忙

J2EE 码拜 9年前 (2016-03-14) 2541次浏览
CXF调用WEBSERVICES时异常,折腾几天了,求高手帮忙!程序如下:
package com.srv;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
public class testSms {
public static  void main(String[] args)  {
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory
.newInstance();
Client client = clientFactory.createClient(“http://fy.webxml.com.cn/webservices/EnglishChinese.asmx?wsdl”);
try {
Object[] result = client.invoke(“TranslatorReferString”, new Object[] {“we”});
} catch (Exception e) {
e.getStackTrace();
}
}
===================================================================
程序运行到:Client client = clientFactory.createClient(“http://fy.webxml.com.cn/webservices/EnglishChinese.asmx?wsdl”);
时,出现以下异常:
Exception in thread “main” java.lang.reflect.UndeclaredThrowableException
at $Proxy18.bind(Unknown Source)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:273)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:198)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:191)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:146)
at com.srv.testSms.main(testSms.java:21)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invokeSS(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:52)
… 6 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy20.error(Unknown Source)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.error(SchemaCompilerImpl.java:251)
at com.sun.tools.internal.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:434)
at com.sun.tools.internal.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:425)
at com.sun.tools.internal.xjc.reader.internalizer.Internalizer.move(Internalizer.java:251)
at com.sun.tools.internal.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:105)
at com.sun.tools.internal.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:68)
at com.sun.tools.internal.xjc.reader.internalizer.DOMForest.transform(DOMForest.java:416)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:187)
… 11 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:52)
… 20 more
Caused by: java.lang.RuntimeException: Error compiling schema from WSDL at {http://211.139.26.237:12008/qxtapi/Service.asmx?wsdl}: The “jaxb:globalBindings” customization is not associated with any schema element.
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory$InnerErrorListener.error(DynamicClientFactory.java:581)
… 25 more
Caused by: com.sun.istack.internal.SAXParseException2: The “jaxb:globalBindings” customization is not associated with any schema element.
at com.sun.tools.internal.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:431)
… 17 more
解决方案

40

使用eclipse生成web service客户端,new->other->web service client

iimport cn.com.WebXml.EnglishChineseSoapProxy;
public class TestCilent {
	public static void main(String[] args) throws Exception {
		EnglishChineseSoapProxy ecsp=new EnglishChineseSoapProxy();
		String[]  ret=ecsp.translatorReferString("we");
		for(String str:ret){
 		System.out.println(str);
		}
	}
}

可执行
Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
在lib中加入上面两个类的jar包  应该可以解决


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明CXF调用WEBSERVICES时异常,折腾几天了,求高手帮忙
喜欢 (0)
[1034331897@qq.com]
分享 (0)