[英]Change WSDL xsd:complexType name with Apache CXF
I use Apache CXF to publish a webservice, generating the WSDL "on-the-fly". 我使用Apache CXF发布Web服务,“即时”生成WSDL。 This works great, but I would like to change the naming convention of the generated types.
这很好用,但我想更改生成类型的命名约定。 As the service clients (C#) generate code based on the WSDL, the default xsd:complexType naming results in type names starting with lower-case letters.
当服务客户端(C#)基于WSDL生成代码时,默认的xsd:complexType命名会导致以小写字母开头的类型名称。
Here is an excerpt from the generated WSDL: 以下是生成的WSDL的摘录:
<xs:complexType name="protocolItem">
<xs:sequence>
<xs:element minOccurs="0" name="data" type="tns:protocolItemData"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="elements" nillable="true" type="tns:protocolElement"/>
<xs:element minOccurs="0" name="meta" type="tns:protocolItemMeta"/>
</xs:sequence>
</xs:complexType>
This is the Java code that results in the above WSDL fragment: 这是导致上述WSDL片段的Java代码:
@RooJavaBean
public class ProtocolItem {
private ProtocolItemData data;
private ProtocolItemMeta meta;
private List<ProtocolElement> elements;
}
How can I change the generated WSDL to use something like <xs:complexType name="ProtocolItem">
? 如何更改生成的WSDL以使用类似
<xs:complexType name="ProtocolItem">
?
Hopefully I am not missing a obvious annotation... Thanks! 希望我没有错过明显的注释......谢谢!
EDIT : thanks for the first answer! 编辑 :谢谢你的第一个答案! So there is a way to do this "per class" - can I configure the CXF naming conventions?
所以有一种方法可以“按类”执行此操作 - 我可以配置CXF命名约定吗? Would be nice if I did not need to annotate all classes.
如果我不需要注释所有类,那将会很好。
Try this: 试试这个:
@XmlType(name="ProtocolItem")
public class ProtocolItem {
...
}
Hope this helps. 希望这可以帮助。
Using the Aegis data binding instead of the JAXB data binding with Apache CXF helped: This changed the naming convention. 使用Aegis数据绑定代替与Apache CXF的JAXB数据绑定有助于:这改变了命名约定。 Unfortunately, I realised this after having added all @XmlType annotations, so I removed them again...
不幸的是,我在添加了所有@XmlType注释后意识到这一点,所以我再次将它们删除了......
I stumbled over Aegis when searching for a solution for collections/arrays - they are not wrapped with JAXB, but with Aegis, which is required for proper client code generation (typed collections instead of arrays). 我在搜索集合/数组的解决方案时偶然发现了Aegis - 它们不是用JAXB包装的,而是用Aegis包装的,这是正确的客户端代码生成所必需的(类型集合而不是数组)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.