CXF代码第一个Web服务正在使用xs:element form ="unqualified"创建wsdl.不选择名称空间 [英] CXF code first webservice is creating wsdl with xs:element form="unqualified" not picking up namespace
问题描述
我正在使用代码优先方法通过CXF创建Web服务. 我想使用名称空间,因此 elementFormDefault 设置为 true . WSDL很好,除了复杂类型中嵌入的元素外,我得到了带有 form ="unqualified" 标记的xs:element.但是我想摆脱 form = unqualified 标记
I'm creating webservices with CXF using the code first approach. I want to use namespaces, and therefore elementFormDefault is set to true. The WSDL is fine, except for the elements embedded in the complextypes, i get following xs:element having a form="unqualified" tag. But I want to get rid of the form=unqualified tag
<xs:element form="unqualified" name="LikeSearch" type="xs:boolean"/>
我的package-info.java看起来像这样:
My package-info.java looks like this:
@javax.xml.bind.annotation.XmlSchema(namespace="http://registry.erpel.at",
attributeFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package at.erpel.registry.services.webservice;
Java端点如下:
@WebService(targetNamespace = "http://registry.erpel.at", name="CompanyEndpoint")
public interface CompanyEndpoint {
List<Company> findCompanies(
@WebParam(name = "FindCompaniesRequest") @XmlElement(required=true) FindCompaniesRequest findCompaniesRequest)
throws ServiceFault ;
这是FindCompaniesRequest:
This is the FindCompaniesRequest:
@XmlRootElement(name = "FindCompaniesRequest")
public class FindCompaniesRequest extends AbstractRequestType implements Serializable
{
@XmlElement(name = "LikeSearch", required = true)
protected boolean likeSearch;
...
}
最后是WSDL:
<xs:complexType name="FindCompaniesRequest">
<xs:complexContent>
<xs:extension base="tns:AbstractRequestType">
<xs:sequence>
<xs:element form="unqualified" name="LikeSearch" type="xs:boolean"/>
我想要的是摆脱 form ="unqualified" 标签
到目前为止,我发现的唯一解决方案是将命名空间属性添加到每个XMLElement:
The only solution I have found so far is adding the namespace attribute to every single XMLElement:
@XmlElement(name = "LikeSearch", required = true, namespace="http://registry.erpel.at")
protected boolean likeSearch;
但是我希望子元素只是从父元素中获取命名空间.我尝试将名称空间属性添加到方法描述中的@XMLRootElement批注,@WebParam批注和@XmlElement批注中,但是没有成功.
But I want the child elements just to pick up the namespace from the parent elements. I have tried adding the namespace attribute to the @XMLRootElement annotation, to the @WebParam annotation, and to the @XmlElement annotation in the method description, but without any success.
有人知道如何使它正常工作吗?
Anyone knows how to get this working?
推荐答案
package-info.java
文件只能声明同一包中的类的JAXB默认值.您必须在每个工具包中放置一个 软件包,以进行类生成(或定义批注的更多属性,这没什么好玩的.)
The package-info.java
file can only declare JAXB defaults for the classes in the same package; you've got to put one in each package that gets tooled into doing class generation (or define a whole lot more attributes of your annotations, which isn't much fun).
幸运的是,这几乎是剪切粘贴粘贴的代码.如果要更改名称空间,只需复制一个软件包信息文件并对其进行调整即可.
Fortunately, this is pretty much cut-n-paste coding. Just copy a single package info file around and tweak it if you want the namespace to change.
这篇关于CXF代码第一个Web服务正在使用xs:element form ="unqualified"创建wsdl.不选择名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!