简体   繁体   English

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

[英]How to specify Data type in WSDL when exposed from CXF

I created a simple webservice which accepts a customer object which has two parameters integer and string as follows 我创建了一个简单的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;
}

Exposed it in CXF-servelet.xml 在CXF-servelet.xml中公开

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

The WSDL generated is 生成的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>

From SoapUI tool if I generate request it looks like 从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>

It does not say name is string and age should integer. 它没有说名字是字符串,年龄应该是整数。

How to include the type definitions in WSDL? 如何在WSDL中包括类型定义? What extra coding/annotation/configuration is needed? 需要什么额外的编码/注释/配置?

ANSWER Above WSDL is correct. 回答 WSDL以上是正确的。 In SoapUI tool when I used "Form" view it showed the data types. 在SoapUI工具中,当我使用“窗体”视图时,它显示了数据类型。 在此处输入图片说明

But SoapUI tool does not restrict us the match values to required data type. 但是SoapUI工具不会将匹配值限制为所需的数据类型。 As pointed in the accepted answer, the WSDL points to another file that contains the data types viz. 正如接受的答案中指出的那样,WSDL指向另一个包含数据类型viz的文件。 wsdl:import location="http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl wsdl:import location =“ http:// localhost:8080 / webserviceWithCXFWebApp / servicewala / services / sayHelloService?wsdl = HelloWorld.wsdl

SoapUI tool automatically handles downloading and consuming this file. SoapUI工具会自动处理该文件的下载和使用。

The WSDL you posted does not contain any type information. 您发布的WSDL不包含任何类型信息。 It only contains the binding of soap operations and services. 它仅包含肥皂操作和服务的绑定。 Please go to this URL for the type information: 请转到此URL以获取类型信息:

http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl HTTP://本地主机:8080 / webserviceWithCXFWebApp / servicewala /服务/ sayHelloService WSDL =的HelloWorld.wsdl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM