views:

810

answers:

2

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  A: 

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
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 ??
klerik123456
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
A: 

Thx, ok I have one question:

I have class, with variable num:

public class EncryptMessage : SoapExtension
{
public int num=10;
....
}

Soap extension on web method:

public class Service1 : System.Web.Services.WebService
{
public const string k = "something";

/*in this place I want call some methods, which change variable num in class EncryptMessage,
before than is soap extension used on web method .. it is possible ??If yes, how can I change variable in class EncryptMessage*/

int num2=5;
someMethods(num2); // this methods change variable num in class EncryptMessage

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

I want call some methods, which change variable num in class EncryptMessage, before than is soap extension used on web method .. it is possible ??If yes, how can I change variable in class EncryptMessage.

klerik123456
Please ask each question as a separate question.
John Saunders