从 WSDL 生成代码会导致异常

发布于 2024-11-02 04:28:27 字数 9138 浏览 5 评论 0原文

我正在使用 Axis2 1.5.1 (wsdl2java) 从给定的 WSDL 文件生成代码(客户端存根)。
Web 服务由外部应用程序提供。

<?xml version="1.0" encoding="utf-8"?>  
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility- 1.0.xsd"  
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"   
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"             
xmlns:tns="http://tempuri.org/"   
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"     
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:i0="http://schemas.microsoft.com/ws/2005/02/mex/bindings" 
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"   
xmlns:wsa10="http://www.w3.org/2005/08/addressing"   
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"   
name="service" targetNamespace="http://tempuri.org/"   
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">  
<wsdl:types>  
<xsd:schema targetNamespace="http://tempuri.org/Imports">  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication0.xsd" />  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication1.xsd" />  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication2.xsd" />  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication3.xsd" />  
</xsd:schema>  
</wsdl:types>  
...  
</wsdl:definition>  

RemoteApplication0.xsd内容如下:

<?xml version="1.0" encoding="utf-8"?>  
<xs:schema xmlns:tns="http://schemas.microsoft.com/Message" 
elementFormDefault="qualified"  
targetNamespace="http://schemas.microsoft.com/Message"  
xmlns:xs="http://www.w3.org/2001/XMLSchema">  
<xs:complexType name="MessageBody">  
<xs:sequence>  
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" />  
</xs:sequence>  
</xs:complexType>  
</xs:schema>  

命令行:

wsdl2java -ss -g -d adb -or -p com.sampleapp.ws.generated.client -uri SampleRemoteProcess.wsdl  

生成过程出现异常。
stacktrace:

Using AXIS2_HOME: C:\develop\axis2-1.5.1-bin\axis2-1.5.1\
Using JAVA_HOME: C:\Program Files\Java\jdk1.6.0_21
Retrieving document at 'C:\temp\SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication0.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication1.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication2.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication3.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
[ERROR] org.apache.ws.commons.schema.XmlSchemaException:  

An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
java.lang.RuntimeException: org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports, but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1904)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1927)  
at org.apache.ws.commons.schema.SchemaBuilder.handleInclude(SchemaBuilder.java:1653)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:219)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:433)  
at org.apache.axis2.description.WSDLToAxisServiceBuilder.getXMLSchema(WSDLToAxisServiceBuilder.java:144)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.copyExtensibleElements(WSDL11ToAxisServiceBuilder.java:2319)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:413)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:402)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:346)  
at org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder.populateAllServices(WSDL11ToAllAxisServicesBuilder.java:107)  
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerationEngine.java:147)  
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)  
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)  
Caused by: org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder$2.validate(SchemaBuilder.java:1679)  
at org.apache.ws.commons.schema.SchemaBuilder.setNamespaceAttributes(SchemaBuilder.java:369)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:134)  
at org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:121)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:445)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:368)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1898)  
... 13 more  

Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL  
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerationEngine.java:153)  
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)  
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)  
Caused by: org.apache.axis2.AxisFault:  
org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:396)  
at org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder.populateAllServices(WSDL11ToAllAxisServicesBuilder.java:107)  
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerationEngine.java:147)  
... 2 more    

Caused by: java.lang.RuntimeException:  
org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1904)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1927)  
at org.apache.ws.commons.schema.SchemaBuilder.handleInclude(SchemaBuilder.java:1653)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:219)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:433)  
at org.apache.axis2.description.WSDLToAxisServiceBuilder.getXMLSchema(WSDLToAxisServiceBuilder.java:144)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.copyExtensibleElements(WSDL11ToAxisServiceBuilder.java:2319)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:413)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:402)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:346)  
... 4 more  

An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder$2.validate(SchemaBuilder.java:1679)  
at org.apache.ws.commons.schema.SchemaBuilder.setNamespaceAttributes(SchemaBuilder.java:369)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:134)  
at org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:121)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:445)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:368)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1898)  
... 13 more  

似乎存在命名空间问题,但我不知道如何修复它。
有人可以给我提示吗!

I'm using Axis2 1.5.1 (wsdl2java) for code generation (client stubs) from a given WSDL file.
The webservice is provided by an external application.

<?xml version="1.0" encoding="utf-8"?>  
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility- 1.0.xsd"  
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"   
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"             
xmlns:tns="http://tempuri.org/"   
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"     
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" 
xmlns:i0="http://schemas.microsoft.com/ws/2005/02/mex/bindings" 
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"   
xmlns:wsa10="http://www.w3.org/2005/08/addressing"   
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"   
name="service" targetNamespace="http://tempuri.org/"   
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">  
<wsdl:types>  
<xsd:schema targetNamespace="http://tempuri.org/Imports">  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication0.xsd" />  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication1.xsd" />  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication2.xsd" />  
<xsd:include schemaLocation="SampleApp.App.ApplicationManager.RemoteApplication3.xsd" />  
</xsd:schema>  
</wsdl:types>  
...  
</wsdl:definition>  

Content of RemoteApplication0.xsd is as follows:

<?xml version="1.0" encoding="utf-8"?>  
<xs:schema xmlns:tns="http://schemas.microsoft.com/Message" 
elementFormDefault="qualified"  
targetNamespace="http://schemas.microsoft.com/Message"  
xmlns:xs="http://www.w3.org/2001/XMLSchema">  
<xs:complexType name="MessageBody">  
<xs:sequence>  
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" />  
</xs:sequence>  
</xs:complexType>  
</xs:schema>  

commandline:

wsdl2java -ss -g -d adb -or -p com.sampleapp.ws.generated.client -uri SampleRemoteProcess.wsdl  

Generation process causes an exception.
stacktrace:

Using AXIS2_HOME: C:\develop\axis2-1.5.1-bin\axis2-1.5.1\
Using JAVA_HOME: C:\Program Files\Java\jdk1.6.0_21
Retrieving document at 'C:\temp\SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication0.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication1.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication2.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
Retrieving schema at 'SampleApp.App.ApplicationManager.RemoteApplication3.xsd', relative to 'file:/C:/temp/SampleRemoteProcess.wsdl'.
[ERROR] org.apache.ws.commons.schema.XmlSchemaException:  

An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
java.lang.RuntimeException: org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports, but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1904)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1927)  
at org.apache.ws.commons.schema.SchemaBuilder.handleInclude(SchemaBuilder.java:1653)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:219)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:433)  
at org.apache.axis2.description.WSDLToAxisServiceBuilder.getXMLSchema(WSDLToAxisServiceBuilder.java:144)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.copyExtensibleElements(WSDL11ToAxisServiceBuilder.java:2319)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:413)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:402)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:346)  
at org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder.populateAllServices(WSDL11ToAllAxisServicesBuilder.java:107)  
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerationEngine.java:147)  
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)  
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)  
Caused by: org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder$2.validate(SchemaBuilder.java:1679)  
at org.apache.ws.commons.schema.SchemaBuilder.setNamespaceAttributes(SchemaBuilder.java:369)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:134)  
at org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:121)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:445)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:368)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1898)  
... 13 more  

Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL  
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerationEngine.java:153)  
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)  
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)  
Caused by: org.apache.axis2.AxisFault:  
org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:396)  
at org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder.populateAllServices(WSDL11ToAllAxisServicesBuilder.java:107)  
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerationEngine.java:147)  
... 2 more    

Caused by: java.lang.RuntimeException:  
org.apache.ws.commons.schema.XmlSchemaException:  
An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1904)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1927)  
at org.apache.ws.commons.schema.SchemaBuilder.handleInclude(SchemaBuilder.java:1653)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:219)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:433)  
at org.apache.axis2.description.WSDLToAxisServiceBuilder.getXMLSchema(WSDLToAxisServiceBuilder.java:144)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.copyExtensibleElements(WSDL11ToAxisServiceBuilder.java:2319)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:413)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.processTypes(WSDL11ToAxisServiceBuilder.java:402)  
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:346)  
... 4 more  

An included schema was announced to have the default target namespace  
or the target namespace http://tempuri.org/Imports,  
but has the target namespace http://schemas.microsoft.com/Message  
at org.apache.ws.commons.schema.SchemaBuilder$2.validate(SchemaBuilder.java:1679)  
at org.apache.ws.commons.schema.SchemaBuilder.setNamespaceAttributes(SchemaBuilder.java:369)  
at org.apache.ws.commons.schema.SchemaBuilder.handleXmlSchemaElement(SchemaBuilder.java:134)  
at org.apache.ws.commons.schema.SchemaBuilder.build(SchemaBuilder.java:121)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:445)  
at org.apache.ws.commons.schema.XmlSchemaCollection.read(XmlSchemaCollection.java:368)  
at org.apache.ws.commons.schema.SchemaBuilder.resolveXmlSchema(SchemaBuilder.java:1898)  
... 13 more  

Seems there is a namespace problem, but i dont know how to fix it.
Can anybody give me a hint!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你没皮卡萌 2024-11-09 04:28:27

问题是你使用了“include”。 “包含”模式必须与包含项所在的模式具有相同目标命名空间(实际上,您将相同的命名空间拆分到多个文件中)。您必须“导入”模式才能使用具有不同目标命名空间的另一个模式文件。

the problem is your use of "include". "include"ed schemas must have the same target namespace as the schema in which the include resides (you are esentially splitting the same namespace across multiple files). you must "import" a schema to use another schema file with a different target namespace.

陪你到最终 2024-11-09 04:28:27

错误消息非常具有描述性:在另一个架构中 的架构始终需要与导入架构具有相同的目标命名空间。在文件 RemoteApplication0.xsd 中,您必须将目标命名空间 http://schemas.microsoft.com/Message 更改为 http://tempuri.org/Imports

The error message is pretty descriptive: A schema that is <include>'ed in another schema always needs to have the same target namespace as the importing schema. In the file RemoteApplication0.xsd you have to change the target namespace http://schemas.microsoft.com/Message to http://tempuri.org/Imports.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文