how to remove <optional> from Soap request

7.5k Views Asked by At

I am using SoapUI Pro 4.6.1 for testing my WCF service. And my request look like this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
       <soapenv:Header/>
    <soapenv:Body>
  <tem:doPaymentRequest>
     <!--Optional:-->
     <tem:credentials>
        <!--Optional:-->
        <tem:accountId>?</tem:accountId>
        <!--Optional:-->
        <tem:userName>?</tem:userName>
        <!--Optional:-->
        <tem:password>?</tem:password>
     </tem:credentials>
     </tem:doPaymentRequest>

How to remove --Optional:--> from SOAP I am using message format to wrap my data contract and i am using isRequired attribute for DataContract.

3

There are 3 best solutions below

1
On
[DataContract]
public class GetColorsRS
{
    DataMember(Name = "Errors", Order = 1, IsRequired=false)]
    public List<Error> Errors { get; set; }
}
1
On

You need to specify [DataMember(IsRequired = true)] on all of the properties in the data contract class, then they won't be optional.

0
On

Do you want to remove any oprional element? Then File -> Preferences -> WSDL Settings -> Include Optional (this is a checkbox). When you add request to your test case it also suggests to select option "Create optional elements".