I've created an WebService proxy class based on a WSDL (in my Visual Studio 2010 .NET solution).
Now what I need is, that the soap header of my request to the remote web service have a specific format, imagine something with two or three fields is not very relevant.
So my solution was, I edited the code generated by Visual Studio and commented out the method where i needed that custom soap header.
Next, because the web service class is marked as partial, I created safe code (that cannot be touched by the generator) in a class with the same name of the generated one (so it's the same class) and declared there the method commented out previously.
I declared it like this:
//this is the generated code file
public partial class Invoices: InvoicesWS.invoices
{
//[System.Web.Services.Protocols.SoapDocumentMethodAttribute( ...
//public RegisterInvoiceResponseType RegisterInvoice(RegisterInvoiceType ...)
//{ ... }
}
//this is the class I created else where in my project
public partial class Invoices: InvoicesWS.invoices
{
public SecureSoapHeader Security { get; set; }
[SoapHeader("Security", Direction = SoapHeaderDirection.In)]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(
"http://someurl.pt/invoices/RegisterInvoice",
Use = System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare),
TraceExtension()]
public RegisterInvoiceResponseType RegisterInvoice(RegisterInvoiceType RegisterInvoiceElem)
{
object[] results =
this.Invoke("RegisterInvoice", new object[] {RegisterInvoiceElem});
return ((RegisterInvoiceResponseType)(results[0]));
}
}
So, to make my proxy class send a custom header I did this. But every time I remember to update the web reference, I'll have to manually comment out the method above that is being generated by the Visual Studio tool, to avoid conflicts due to having to methods with the same signature.
Is there a better way, or best practice to address this situation?
Please do not advise me to do it with WCF, I know the solution for that, but correctly this is the code that has been working and changing it at this time is not a possibility.
Thanks.