首页 文章

从CXF公开时如何在WSDL中指定数据类型

提问于
浏览
2

我创建了一个简单的Web服务,它接受一个客户对象,该对象有两个参数integer和string,如下所示

@WebService(endpointInterface="com.kaushik.serverside.intf.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
    @Resource
    WebServiceContext wsctx;
    public String getHelloWorldAsString1(Customer customer) {
}
@XmlRootElement
public class Customer {
    public String firstName;
    public int age;
}

将它暴露在CXF-servelet.xml中

<bean id="hello" class="com.kaushik.serverside.impl.HelloWorldImpl"></bean>
    <jaxws:endpoint id="sayHelloEndpoint"
        implementor="#hello" address="/services/sayHelloService" />

生成的WSDL是

<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.serverside.kaushik.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/wsdl/soap/http" xmlns:ns1="http://intf.serverside.kaushik.com/" targetNamespace="http://impl.serverside.kaushik.com/" name="HelloWorldImplService">
<wsdl:import namespace="http://intf.serverside.kaushik.com/" location="http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl"> </wsdl:import>
<wsdl:binding name="HelloWorldImplServiceSoapBinding" type="ns1:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getHelloWorldAsString1">
<soap:operation style="document" soapAction=""/>
<wsdl:input name="getHelloWorldAsString1">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getHelloWorldAsString1Response">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldImplService">
<wsdl:port name="HelloWorldImplPort" binding="tns:HelloWorldImplServiceSoapBinding">
<soap:address location="http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

从SoapUI工具,如果我生成请求它看起来像

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:intf="http://intf.serverside.kaushik.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <intf:getHelloWorldAsString1>
         <!--Optional:-->
         <arg0>
            <!--Optional:-->
            <firstName>?</firstName>
            <age>?</age>
         </arg0>
      </intf:getHelloWorldAsString1>
   </soapenv:Body>
</soapenv:Envelope>

它没有说name是字符串而age应该是整数 .

如何在WSDL中包含类型定义?需要什么额外的编码/注释/配置?

ANSWER 以上WSDL是正确的 . 在SoapUI工具中,当我使用"Form"视图时,它显示了数据类型 .
enter image description here

但SoapUI工具不会将匹配值限制为所需的数据类型 . 正如接受的答案所指出的,WSDL指向另一个包含数据类型的文件 . wsdl:import location =“http:// localhost:8080 / webserviceWithCXFWebApp / servicewala / services / sayHelloService?wsdl = HelloWorld.wsdl

SoapUI工具自动处理下载和使用此文件 .

1 回答

相关问题