ASMX Web Service Soap Extension - How to inject an attribute into a client proxy class?

I am trying to set client side soap extension attributes. 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 in web method:

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

      

Implementation in the 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: [EncryptMessage ( StrKey = "pass")]

I want to set the client side soap extension attribute before using Soap extension when I call some web methods.

Example: I am calling some method that sets the soap extension attributes on both sides before the soap extension is used. Can anyone help me?

+2


source to share


1 answer


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



See SoapExtensionReflector and SoapExtensionImporter anyway . Please note that they will only work for .NET, ASMX clients.

+2


source







All Articles