JAX-WS: why nested elements are in "" namespace?

11,820

Solution 1

This behavior is proper per the WSI-Basic Profile. If you look at:

http://www.ws-i.org/profiles/basicprofile-1.1.html#Part_Accessors

section 4.7.20, assertion R2735 specifically states that for RPC/Literal, the part accessor elements must be put in elements with no namspace.

Solution 2

I too have the same problem . i developed webservice clientusing JAX-WS, with SOAP UI simulation.My webservice client is working fine. but when i test with real server (axis web service). I got null values.

SOUP UI simulation response like this

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservice.aml.infrasofttech.biz" xmlns:dat="http://dataobject.aml.infrasofttech.biz">
   <soapenv:Header/>
   <soapenv:Body>
      <web:getCIPMatchResponse>
         <!--1 or more repetitions:-->
         <web:getCIPMatchReturn>
            <dat:countries>?</dat:countries>
            <dat:dob>?</dat:dob>
            <dat:fullName>?</dat:fullName>
            <dat:isError>?</dat:isError>
            <dat:listName>?</dat:listName>
            <dat:passport>?</dat:passport>
            <dat:percentage>?</dat:percentage>
            <dat:sdnId>?</dat:sdnId>
            <dat:sdnName>?</dat:sdnName>
         </web:getCIPMatchReturn>
      </web:getCIPMatchResponse>
   </soapenv:Body>
</soapenv:Envelope>

But in the server it response with out namespace like this..

        <countries>?</countries>
        <dob>?</dob>
        <fullName>?</fullName>
        <isError>?</isError>
        <listName>?</listName>
        <passport>?</passport>
        <percentage>?</percentage>
        <sdnId>?</sdnId>
        <sdnName>?</sdnName>

The JAX-WS generated code looks like this.

  @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SdnBean", namespace = "http://dataobject.aml.infrasofttech.biz", propOrder = {
    "countries",
    "dob",
    "fullName",
    "isError",
    "listName",
    "passport",
    "percentage",
    "sdnId",
    "sdnName"
})
public class SdnBean {

Then i have change the client jax-ws code @XmlType as shown below

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "countries",
    "dob",
    "fullName",
    "isError",
    "listName",
    "passport",
    "percentage",
    "sdnId",
    "sdnName"
})
public class SdnBean {

Now this will bind the soap response without namespace.

Share:
11,820
Vladimir Dyuzhev
Author by

Vladimir Dyuzhev

Software Consultant

Updated on June 04, 2022

Comments

  • Vladimir Dyuzhev
    Vladimir Dyuzhev about 2 years

    Having a toy service as below

    @WebService(targetNamespace="http://www.example.org/stock")
    @SOAPBinding(style=Style.RPC,parameterStyle=ParameterStyle.WRAPPED)
    public class GetStockPrice {
        @WebMethod(operationName="GetStockPrice",action="urn:GetStockPrice")
        @WebResult(partName="Price")
        public Double getPrice(
                @WebParam(name="StockName")
                String stock
            ) {
            return null;
        }
    }
    

    JAX-WS-generated client creates a SOAP message where StockName parameter has no namespace:

    <?xml version='1.0' encoding='UTF-8'?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
        <ns2:GetStockPrice xmlns:ns2="http://www.example.org/stock">
          <StockName>IBM</StockName>
        </ns2:GetStockPrice>
      </S:Body>
    </S:Envelope>
    

    I would expect and wish StockName to be generated as

      <ns2:StockName>IBM</ns2:StockName>
    

    i.e. in the target namespace, not in the anonymous one (ns2 is not default, as far as I can see from the message).

    I wonder how to make JAX-WS to add the target namespace to the nested elements of the message?

    An attempt to specify the namespace to WebParam annotation changed nothing as this param is ignored when RPC is used.

    Or... Does it mean that parameters in RPC-style are always anonymous?

    UPDATE

    Silly me. Partially solved. What I had to do is

    • style=Document, to enable target namespaces for elements
    • param style=Wrapped, to enable top level element
    • specify target namespace for WebParam (why service one is not used? documentation says service namespace should be used)

    That is:

    @WebService(targetNamespace="http://www.example.org/stock")
    @SOAPBinding(style=Style.DOCUMENT,parameterStyle=ParameterStyle.WRAPPED)
    public class GetStockPrice {
        @WebMethod(operationName="GetStockPrice",action="urn:GetStockPrice")
        @WebResult(partName="Price")
        public Double getPrice(
                @WebParam(name="StockName",targetNamespace="http://www.example.org/stock")
                String stock
            ) {
            return null;
        }
    }
    

    Still, client still expects return value without any namespace, even if I try to declare provide one. This is confusing.

  • ericpeters
    ericpeters over 7 years
    This is an interesting answer/reference document, but my understanding is that it only applies to the RPC/Literal and not the Document/Literal - which would be expected to have the proper namespace & prefixes. There is an example SOAP request in the WSDL Specification that includes the child-namespace prefix: w3.org/TR/wsdl#_Toc492291097 JAX-WS does seem to honor/include the proper XML namespaces even in the "Document" mode - is there another spec I'm missing?
  • ericpeters
    ericpeters over 7 years
    "elementFormDefault" This is extremely important for looking at the WSDL to see if they define whether the <StockName>IBM</StockName> is namespace prefixed or not.