ASMX Web Service Soap Extension - How to Inject Attribute into Client Proxy Class?

3.5k Views Asked by At

I try set soap extension attributes on client side. For example:

Implementation in web service:

[AttributeUsage(AttributeTargets.Method)]
public class EncryptMessageAttribute : SoapExtensionAttribute
{
    private string strKey="null";

    public string StrKey
    {
        get {  return strKey; }

        set { strKey = value; }    
    }
}

Soap extension class:

public class EncryptMessage : SoapExtension
{
...
}

Used on web method:

[WebMethod]
[EncryptMessage( StrKey = "pass")]
public string test2()
{
    return "ok";
}

Implementation in Proxy class:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/test", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[EncryptMessage( StrKey = "pass")]
public string test() {
    object[] results = this.Invoke("test", new object[0]);
    return ((string)(results[0]));
}

Soap extension attributes are::[EncryptMessage( StrKey = "pass")]

I want to set Soap Extension Attribute on client side, before than I use Soap Extension, when I call some web methods.

Example: I call some method, wich set soap extension attributes on both side, before than soap extension is used. Can somebody help me ?

1

There are 1 best solutions below

2
On

First of all, if you can use WCF for this, then you should. Microsoft has stated that ASMX web services are "legacy technology", and that all new web service development should use WCF.

In any case, see the SoapExtensionReflector and SoapExtensionImporter classes. Note that these will only work for .NET, ASMX clients.