我正在尝试使用apache-cxf创建客户端
我需要运行以下网络服务http://soapclient.com/xml/soapresponder.wsdl
我想要实现的是我将为此服务提供两个参数并返回结果/响应。
以下是我的代码:
JaxWsDynamicClientFactory dfc = JaxWsDynamicClientFactory.newInstance();
Client client = dfc.createClient("http://soapclient.com/xml/soapresponder.wsdl");
Object res[] = client.invoke("echo", "test echo");
System.out.println("Result: " + res[0]);
我收到很多错误,例如:
Exception in thread "main" java.lang.RuntimeException: Fatal error compiling schema from WSDL at {http://soapclient.com/xml/soapresponder.wsdl}: Unexpected <schema> appears at line 9 column 5
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory$InnerErrorListener.fatalError(DynamicClientFactory.java:759)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:90)
at com.sun.proxy.$Proxy22.fatalError(Unknown Source)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.fatalError(SchemaCompilerImpl.java:322)
at com.sun.tools.xjc.util.ErrorReceiverFilter.fatalError(ErrorReceiverFilter.java:87)
at com.sun.xml.xsom.impl.parser.ParserContext$2.fatalError(ParserContext.java:211)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:506)
at com.sun.xml.xsom.impl.parser.state.NGCCHandler.unexpectedEnterElement(NGCCHandler.java:194)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:443)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:258)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:108)
at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:150)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:128)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:193)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:147)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:92)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:100)
at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:104)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:269)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:347)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:128)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:168)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:157)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:534)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:269)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:90)
at com.sun.proxy.$Proxy20.bind(Unknown Source)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:321)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:241)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:234)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
at TestCAse.main(TestCAse.java:8)
Caused by: org.xml.sax.SAXParseExceptionpublicId: http://soapclient.com/xml/soapresponder.wsdl; systemId: http://soapclient.com/xml/soapresponder.wsdl; lineNumber: 9; columnNumber: 5; Unexpected <schema> appears at line 9 column 5
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:499)
... 35 more
答案 0 :(得分:2)
它失败了,因为在该地址发布的WSDL无效。 CXF抱怨的具体故障点是:
<types>
<schema xmlns="http://www.w3.org/1999/XMLSchema" targetNamespace="http://www.SoapClient.com/xml/SoapResponder.xsd"></schema>
</types>
注意<schema>
标签的无限制使用?该标记在http://www.w3.org/2001/XMLSchema
命名空间内提供,使用前缀xsd
限定。 WSDL中应该包含:
<types>
<xsd:schema xmlns="http://www.w3.org/1999/XMLSchema" targetNamespace="http://www.SoapClient.com/xml/SoapResponder.xsd"></xsd:schema>
</types>
为什么结果错误超出了我; afterall,命名空间和前缀在wsdl:
的顶部正确声明 xmlns:xsd="http://www.w3.org/2001/XMLSchema".
要解决此问题,请保存该wsdl的本地副本,进行编辑以更正非限定标记的使用,然后在应用程序中使用更正的本地副本