1

在我工作的地方,我们制定了一项政策,规定我们应该尝试“自下而上”(代码优先)构建 Web 服务。

这样做时,如何在我的 XSD <types>WSDL 元素中添加限制?例如,在下面:

import javax.jws.WebService;
import javax.xml.ws.BindingType;

@WebService
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class ProofOfConcept {

    public String sayHello(String guest){
        return "Hello "+guest;
    }
}

我的 WSDL 中的输出如下:

...
<xs:complexType name="sayHello">
    <xs:sequence>
        <xs:element minOccurs="0" name="arg0" type="xs:string" />
    </xs:sequence>
</xs:complexType>
...

我想在“guest”字符串中添加minLengthmaxLength限制。这是否可以通过代码而不是直接编辑 WSDL 来完成?

我知道我可以使用自定义类并使用@XmlElement@XmlAttribute获取一些自定义项(名称、必需等)来注释我的字段,但没有特定于字符串(长度等)之类的东西;是否可以修改/扩展这些注释以添加对长度或模式等内容的支持?

谢谢。

4

1 回答 1

0

I find it interesting that your policy is to try to build Web services bottom-up as I recommend building Web services top-down in order to cleanly define the contract. At any rate...

I'm not aware of a specific solution using annotations and I see that you haven't found one in your search either. If you want to automate the process so as to avoid overwriting your changes to the schema every time you regenerate the WSDL you can add an XSL transform to the resulting WSDL to add these attributes. While not an ideal solution it should allow you to set the attributes and continue working.

于 2010-01-09T04:04:14.427 回答