3

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 ?

John Saunders
  • 160,644
  • 26
  • 247
  • 397

1 Answers1

2

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 1
    I view SoapExtensionReflector and SoapExtensionImporter classes, but on msdn I didn't find any sample, how can I set soap extension attribute with these classes. If you be so good and explane me How can I set/use this classes in my problem ?? –  Sep 13 '09 at 16:37
  • There are no examples because it is too complicated and too prone to error. You should **not** be using ASMX web services! You should be using WCF. – John Saunders Sep 14 '09 at 02:39