C# – How to add SoapExtension attribute to generated web service client proxy without modifying the generated class

cPROXYsoapweb serviceswsdl

I have created a SoapExtension class to capture the soap request and response from specific web service calls. In order to put this SoapExtension into effect, I have to add an attribute to the method in the generated proxy client.

For example, I've added the AuditSoapCapture attribute to this method:

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://blahblah.com/webservices/AddressSearch", RequestNamespace = "http://blahblah.com/webservices/", ResponseNamespace = "http://blahblah.com/webservices/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [blahblah.TriadLite.Core.AuditSoapCapture]
    public System.Data.DataSet AddressSearch(string HouseNumber, string StreetName, string ZipCode) {
        object[] results = this.Invoke("AddressSearch", new object[] {
                    HouseNumber,
                    StreetName,
                    ZipCode});
        return ((System.Data.DataSet)(results[0]));
    }

I am looking for a way to add this attribute to specific methods without modifying the generated client proxy, as they will get lost when we regenerate. Can I do this in a another partial class or interface or some other way?

Thanks!

Best Answer

Unfortunately, you'll need to modify the proxy code. The other possibilities you mention will not work - a parial class will not overwrite existing functionality, and there is no way that I'm aware of getting an interface to do what you need (compounded by the fact that there is no way to even let the proxy generator know that you intend to implement an interface).

Something that I've done in the past, in a situation where you have access to the source of the webservice, is to write a little app that will parse the code (as text) in the .asmx.cs file of the webservice to extract the names of all the methods that are tagged with [WebMethod]. Then the app "fixes up" the References.cs by inserting appropriate attributes onto the proxied methods, based on some settings file or somesuch. This works well because the naming conventions in the proxy map very neatly to the method names in the original service.

Related Topic