c# - How to detect auto-generated method parameters on service proxies?

When I create a proxy to my service, some extra parameters are added as XmlIgnoreAttribute. For example:

Interface method contract declaration:

void AddToList(int integerToAdd);

Method implementation:

public void AddToList(int integerToAdd) {

Now, here is what this method actually looks like when I generate a proxy to my service dynamically:

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/IService1/AddToList", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void AddToList(int integerToAdd, [System.Xml.Serialization.XmlIgnoreAttribute()] bool integerToAddSpecified)
    this.Invoke("AddToList", new object[] {integerToAdd, integerToAddSpecified});

If I have the ParameterInfo object for this parameter, how can I check that this parameter has been marked as XmlIgnoreAttribute?

If this is not a good way to check for these auto-generated parameters, then is there another (better) way to check for them?

Bonus: Will there ever be a case where non-boolean types are generated and marked as XmlIgnoreAttribute?

1 Answer

  1. Lorin- Reply


    I assume you would use ParameterInfo.GetCustomAttributes() ?

    ParameterInfo secondParam = ..
    object[] attribs = 
              secondParam.GetCustomAttributes(typeof(XmlIgnoreAttribute), false);
    //the second bool param is ignored. See the docs.
    //check if => attribs has anything..

    (1) I'm not sure why you're checking these parameters anything so not sure if it's good/better. (2) Not sure about the second question. I assume this is from VS code gen (svcutil?) Maybe some MSFT's who's designed this may know better.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>