从 CXF 公开时如何在 WSDL 中指定数据类型
How to specify Data type in WSDL when exposed from CXF
我创建了一个简单的网络服务,它接受一个客户对象,它有两个参数整数和字符串,如下所示
@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>
没有说名字是字符串,年龄应该是整数。
如何在 WSDL 中包含类型定义?需要什么额外的 coding/annotation/configuration?
回答
以上 WSDL 是正确的。在 SoapUI 工具中,当我使用 "Form" 视图时,它显示了数据类型。
但是 SoapUI 工具并不限制我们将匹配值限制为所需的数据类型。正如接受的答案中所指出的,WSDL 指向另一个包含数据类型的文件,即。 wsdl:import location="http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl
SoapUI 工具自动处理此文件的下载和使用。
您发布的 WSDL 不包含任何类型信息。它只包含 soap 操作和服务的绑定。请转到此 URL 以获取类型信息:
我创建了一个简单的网络服务,它接受一个客户对象,它有两个参数整数和字符串,如下所示
@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>
没有说名字是字符串,年龄应该是整数。
如何在 WSDL 中包含类型定义?需要什么额外的 coding/annotation/configuration?
回答
以上 WSDL 是正确的。在 SoapUI 工具中,当我使用 "Form" 视图时,它显示了数据类型。
但是 SoapUI 工具并不限制我们将匹配值限制为所需的数据类型。正如接受的答案中所指出的,WSDL 指向另一个包含数据类型的文件,即。 wsdl:import location="http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl
SoapUI 工具自动处理此文件的下载和使用。
您发布的 WSDL 不包含任何类型信息。它只包含 soap 操作和服务的绑定。请转到此 URL 以获取类型信息: