2
votes

I created a simple webservice which accepts a customer object which has two parameters integer and string as follows

@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

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

The WSDL generated is

<?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

<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? What extra coding/annotation/configuration is needed?

ANSWER Above WSDL is correct. In SoapUI tool when I used "Form" view it showed the data types. enter image description here

But SoapUI tool does not restrict us the match values to required data type. As pointed in the accepted answer, the WSDL points to another file that contains the data types viz. wsdl:import location="http://localhost:8080/webserviceWithCXFWebApp/servicewala/services/sayHelloService?wsdl=HelloWorld.wsdl

SoapUI tool automatically handles downloading and consuming this file.

1
Can you get the WSDL thats included in the WSDL you posted? localhost:8080/webserviceWithCXFWebApp/servicewala/services/… - Pradeep Pati

1 Answers

0
votes

The WSDL you posted does not contain any type information. It only contains the binding of soap operations and services. Please go to this URL for the type information:

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