How to specify Data type in WSDL when exposed from CXF
我创建了一个简单的Web服务,该服务接受一个客户对象,该对象具有以下两个参数integer和string
1 2 3 4 5 6 7 8 9 10 11 | @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中公开它
1 2 3 | <bean id="hello" class="com.kaushik.serverside.impl.HelloWorldImpl"></bean> <jaxws:endpoint id="sayHelloEndpoint" implementor="#hello" address="/services/sayHelloService" /> |
生成的WSDL是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?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工具开始,它看起来像
1 2 3 4 5 6 7 8 9 10 11 12 13 | <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:intf="http://intf.serverside.kaushik.com/"> <soapenv:Header/> <soapenv:Body> <intf:getHelloWorldAsString1> <!--Optional:--> <!--Optional:--> <firstName>?</firstName> ?</age> </arg0> </intf:getHelloWorldAsString1> </soapenv:Body> </soapenv:Envelope> |
它没有说名称是字符串,并且年龄应该是整数。
如何在WSDL中包括类型定义?需要什么额外的编码/注释/配置?
答案
上面的WSDL是正确的。在SoapUI工具中,当我使用" Form "视图时,它显示了数据类型。
但是SoapUI工具不会将匹配值限制为所需的数据类型。正如接受的答案中指出的那样,WSDL指向另一个包含数据类型viz的文件。 wsdl:import location = " http:// localhost:8080 / webserviceWithCXFWebApp / servicewala / services / sayHelloService?wsdl = HelloWorld.wsdl
SoapUI工具自动处理下载和使用此文件。
您发布的WSDL不包含任何类型信息。它仅包含肥皂操作和服务的绑定。请转到此URL以获取类型信息:
http:// localhost:8080 / webserviceWithCXFWebApp / servicewala / services / sayHelloService?wsdl = HelloWorld.wsdl