我有问题,我想在网络方法中设置肥皂扩展属性:网络服务中的肥皂扩展:
public class EncryptMessageAttribute : SoapExtensionAttribute
{
private string strKey="null";
public void setKey(string s)
{
strKey=s;
}
}
肥皂扩展类:
public class EncryptMessage : SoapExtension
{
....
}
网络方法上的肥皂扩展:
public class Service1 : System.Web.Services.WebService
{
public string k;
[WebMethod]
[EncryptMessageAttribute(setKey(k))]
public string test2()
{
return "ok";
}
[WebMethod]
[EncryptMessage(setKey(k))]
public string test2()
{
return "ok";
}
}
它以这个编译错误结束:
错误 1 当前上下文中不存在名称“setKey”错误 2 非静态字段、方法或属性需要对象引用
更新1:
我试过了:
public class Service1 : System.Web.Services.WebService
{
public const string strAttribute = "something";
[WebMethod]
[EncryptMessage SetKey =strAttribute)]
public string test2()
{
return "ok";
}
}
有用。但是我想在客户端调用 web 方法之前更改属性,这是可能的,或者属性必须是 const ?
例如:public string strAttribute
不起作用。
更新 2:
我有另一个问题:
我有类,变量 num:
public class EncryptMessage : SoapExtension
{
public int num=10;
....
}
网络方法上的肥皂扩展:
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 that 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";
}
}