0

I'm building a code first web service in java and building it with maven. The web service itself works fine but I can't get rid of

minOccurs="0"

in my generated wsdl:

<xs:complexType name="getHOP">
  <xs:sequence>
    <xs:element minOccurs="0" name="getHopRequest" type="getHopRequest"/>
  </xs:sequence>
</xs:complexType>
<xs:element name="getHOPResponse" type="getHOPResponse"/>
<xs:complexType name="getHOPResponse">
  <xs:sequence>
    <xs:element minOccurs="0" name="return" type="getHopResponse"/>
  </xs:sequence>
</xs:complexType>

My interface looks like this

@WebService
public interface GetHop {

GetHopResponse getHOP(
        @WebParam(name = "getHopRequest") GetHopRequest getHopRequest);
}

And this is my request class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getHopRequest", propOrder = { "companyId", "countryIsoCode",
    "currencyIsoCode", "paymentMethodId", "customerId", "totalAmount",
    "cartId", "successUrl", "failureUrl", "notifyUrl" })
public class GetHopRequest {

@XmlElement(required = true)
private String companyId;
@XmlElement(required = true)
private String countryIsoCode;
@XmlElement(required = true)
private String currencyIsoCode;
@XmlElement(required = true)
private String paymentMethodId;
@XmlElement(required = true)
private String customerId;
@XmlElement(required = true)
private String totalAmount;
@XmlElement(required = true)
private String cartId;
@XmlElement(required = true)
private String successUrl;
@XmlElement(required = true)
private String failureUrl;
@XmlElement(required = true)
private String notifyUrl;

// Getter and setter here

}

Already was able to set all elements in the getHopRequest as required by

@XmlElement(required = true)

But I can't figure out how to do this for the request/response itself.

Can anyone tell me how to do this?

Milla
  • 403
  • 1
  • 5
  • 22

2 Answers2

0

This has not be verified nor tested.

You can add the @XmlElement on your Web Service Parameter of your Web method and set required=true, as follows:

@WebService
public interface GetHop {

GetHopResponse getHOP(
        @WebParam(name = "getHopRequest") @XmlElement(required=true) GetHopRequest getHopRequest);
}
Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • Also, reposting another answer isn't really correct behavior. A link in the comments would be better, or, if you think the questions are too similar, a duplicate vote. – Keppil Oct 01 '15 at 07:54
  • @Keppil I answered the question first then looked for a similar answer on Google. Besides, none of the questions found on SO were accepted to vote as a duplicate. – Buhake Sindi Oct 01 '15 at 07:56
  • In that case removing this answer when you found an almost identical one would make sense, right? – Keppil Oct 01 '15 at 08:27
  • well the answer summarizes it a little bit to that what I really needed and it doesn't hurt anyone - unfortunately it also doesn't work ^^ – Milla Oct 01 '15 at 08:46
0

Primitive types and not primitive types may have null values in the marshalled objects. By default they are not required and minOccurs="0" indicate that they may not exist at all.

If you need to remove minOccurs="0" then you should use:

@XmlElement(nillable=false, required=true)

After that the generated WSDL will not include minOccurs, because minOccurs has the default value 1 and it's ignored.

  • Added this in my interface and also tried it in the service but still doesn't work :/ only works fine for all those String types as you can see above but not for the whole request itself – Milla Oct 05 '15 at 05:48