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

时间:2017-05-30 07:38:31

标签: java xml web-services soap wsdl

我创建了一个简单的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工具中,当我使用&#34; Form&#34;查看它显示的数据类型。 enter image description here

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

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

1 个答案:

答案 0 :(得分:0)

您发布的WSDL不包含任何类型信息。它只包含soap操作和服务的绑定。请转到此URL以获取类型信息:

http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl