[Mono-list] XmlIgnore attribute ignored in SOAP client requests in mono 3.2.1

Dave Curylo curylod at asme.org
Tue Oct 1 18:34:28 UTC 2013


I'm migrating projects from running under mono 2.10.8.1 up to mono
3.2.1, and I've come upon an issue where it appears that the
[XmlIgnore] attribute is no longer preventing the SOAP request from
sending some properties.  When I test it directly in the
XmlSerializer, it works as expected (ignoring things marked with
XmlIgnore), but when making SOAP requests, they are passed along.

I’m attaching a sample solution of simple web service and a console
client that illustrates the issue of XmlIgnore attribute ignoring in
proxy class.

SampleWebService (declared in Test.WebService project) is a ASP.NET
web service that exposes one web method:

        [WebMethod]
        public string SampleMethod(string name, int age,
[System.Xml.Serialization.XmlIgnoreAttribute()] bool ageSpecified) {
            …
        }

The service XSD is such:

    <s:schema elementFormDefault="qualified"
targetNamespace="http://sample.webservice.org/">
      <s:element name="SampleMethod">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="name"
type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="age" type="s:int" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="SampleMethodResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1"
name="SampleMethodResult" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>

A key thing here is the parameter “age” of type “int” that is optional.
The proxy generated with wsdl.exe tool contains method:

        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://sample.webservice.org/SampleMethod",
RequestNamespace="http://sample.webservice.org/",
ResponseNamespace="http://sample.webservice.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public string SampleMethod(string name, int age,
[System.Xml.Serialization.XmlIgnoreAttribute()] bool ageSpecified) {
            object[] results = this.Invoke("SampleMethod", new object[] {
                        name,
                        age,
                        ageSpecified});
            return ((string)(results[0]));
        }

The Test.WebService.Client is a simple console application that is
calling SampleWebService:

        static void Main() {
            try {
                var proxy = new SampleWebService { Url =
ConfigurationManager.ConnectionStrings["SampleWebService"].ConnectionString
};
                var result = proxy.SampleMethod("Test", 0, false);
                Console.WriteLine(result);
            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine("Press <enter> to exit...");
            Console.ReadLine();
        }

This app running on Windows .NET or Mono 2.10.8 generates the
following SOAP envelope:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                <soap:Body>
                                <SampleMethod
xmlns="http://sample.webservice.org/">
                                                <name>Test</name>
                                </SampleMethod>
                </soap:Body>
</soap:Envelope>

When running on Mono 3.2.1/3.2.0 the SOAP envelope contains an extra
element “ageSpecified”:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                <soap:Body>
                                <SampleMethod
xmlns="http://sample.webservice.org/">
                                                <name>Test</name>

<ageSpecified>false</ageSpecified>
                                </SampleMethod>
                </soap:Body>
</soap:Envelope>

It looks like Mono 3 has ignored the presence of XmlIgnore attribute
in proxy class for “ageSpecified” parameter when generating the SOAP
envelope. Such SOAP message format is a problem for web services those
contain request validation against XSD.

Is this a known issue or is there a workaround or option so it will
behave as in previous mono versions?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.WebService.zip
Type: application/zip
Size: 20894 bytes
Desc: not available
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20131001/aa3ff68c/attachment-0001.zip>


More information about the Mono-list mailing list