0
votes

I'm trying to create Jax-ws WebServices. But stuck with this behaviour of JAX-WS 2.2.

I wrote the SEI class in the following way

  @WebService
@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED,use=Use.LITERAL,style=Style.DOCUMENT)
        public class WebServicesServlet{
        @WebMethod
        public GetServerTimeProperty getServerTimeProperties(){
        return new GetServerTimeProperty();
        }

    }

The generated wsdl for the above SEI is as follows:

 <types>
    <xsd:schema>
    <xsd:import namespace="http://soapCl.test/" schemaLocation="WebServicesService_schema1.xsd"/>
    </xsd:schema>
    </types>
    <message name="getServerTimeProperties">
    <part name="parameters" element="tns:getServerTimeProperties"> </part>
    </message>
    <message name="getServerTimePropertiesResponse">
    <part name="parameters" element="tns:getServerTimePropertiesResponse"> </part>
    </message>

And the XSD

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://soapCl.test/" version="1.0" targetNamespace="http://soapCl.test/">

<xs:element name="getTimeProperties" type="tns:getServerTimeProperties"/>
<xs:element name="getTimePropertiesResponse" type="tns:getServerTimePropertiesResponse"/>

<xs:complexType name="getServerTimeProperties">
<xs:sequence/>
</xs:complexType>
**<xs:complexType name="getServerTimePropertiesResponse">**
<xs:sequence>
**<xs:element name="return" type="tns:getServerTimeProperty" minOccurs="0"/>**
</xs:sequence>
</xs:complexType>


<xs:complexType name="getServerTimeProperty">
<xs:sequence>
<xs:element name="dayLightSavingHours" type="xs:int"/>
<xs:element name="observesDayLightSavings" type="xs:boolean"/>
<xs:element name="timeZoneDisplayName" type="xs:string"/>
<xs:element name="timeZoneId" type="xs:string"/>
<xs:element name="timeZoneValue" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

SOAP Response :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <dlwmin:getServerTimePropertiesResponse xmlns:dlwmin="http://soapCl.test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <GetServerTimeProperty>
            <dayLightSavingHours>0</dayLightSavingHours>
            <observesDayLightSavings>false</observesDayLightSavings>
         </GetServerTimeProperty>
      </dlwmin:getServerTimePropertiesResponse>
   </soapenv:Body>
</soapenv:Envelope>

I've tried to generate stubs using wsimport and this is what I could observe in the generated port class

@WebMethod
    **@WebResult(targetNamespace = "")**
    @RequestWrapper(localName = "getServerTimeProperties", targetNamespace = "http://soapCl.test/", className = "soapCl.test.GetServerTimeProperties")
    @ResponseWrapper(localName = "getServerTimePropertiesResponse", targetNamespace = "http://soapCl.test/", className = "soapCl.test.GetServerTimePropertiesResponse")
    @Action(input = "http://soapCl.test/WsSessionEJBEndPoint/getServerTimePropertiesRequest", output = "http://soapCl.test/WsSessionEJBEndPoint/getServerTimePropertiesResponse")
    public GetServerTimeProperty getServerTimeProperties();

I'm curious to Know why is the WebResult name different in wsdl as "return" and in soap Response as "GetServerTimeProperty" and in generated stub as "".

Also If I dont annotate the Webmethod with @WebResult(name="GetServerTimeProperty"), my stub-generated client response is null.

If I annotate my webmethod with @WebResult(name="GetServerTimeProperty"), my soapResponse is looking as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns2:getServerTimePropertiesResponse xmlns:ns2="http://soapCl.test/">
         <return>
            <dayLightSavingHours>0</dayLightSavingHours>
            <observesDayLightSavings>false</observesDayLightSavings>
         </return>
      </ns2:getServerTimePropertiesResponse>
   </soapenv:Body>
</soapenv:Envelope>

Is @WebResult(name) is mandatory in jax-ws? I'm curios to Know how this webresult annotation is making a difference in soap response and client response.

Is is that the name should be unique for every "operationName"+"Respone" element ? My wsdl has many elements with same name as

Please Suggest on this why the WebResult name returning soap response as null if we dont annotate

1
the methods do need to either have different names, example if you have two methods with same name but they accept different parameters, the app server is going to complain so you can modify the @WebResult to alleviate the issue.JGlass
@JGlass , Thanks for your input.When I remove <wsdl-file> from my webservices.xml and let appserver generate its own wsdl, I could see the client stubs having no WebResult name. Here my client response is not null. Although my wsdl is not changed. do you think <wsdl-file> tag has some relation with webResult namesushmithaP
I'm sorry, I haven't dealt with IBM web sphere, but IMHO, I wouldn't rely on webservice.xml as it's application server specific, if you ever need to port your code/project yo JBoss or GlassFish you'll introduce additional porting problemsJGlass
All is see that might help you is "The @WebResult annotation customizes the mapping of a return value to a WSDL part or XML element. Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class." from JAX-WS AnnotationsJGlass

1 Answers

0
votes

I Further ruled out this

1.When two webmethods methods have same @WebResult(name="A"), the soapResponse result name differs for two methods when I mention

<wsdl-file>web-inf/wsdl/WebService.wsdl</wsdl-file>

explicitly in webservices.xml.

2.The SoapResponse return name is same when I remove the <wsdl-file> entry in webservices.xml. Not sure how wsdl-file tag is making the difference.