問題があります。Web メソッドで SOAP 拡張属性を設定したい: Web サービスの SOAP 拡張:
public class EncryptMessageAttribute : SoapExtensionAttribute
{
private string strKey="null";
public void setKey(string s)
{
strKey=s;
}
}
SOAP 拡張クラス:
public class EncryptMessage : SoapExtension
{
....
}
Web メソッドの SOAP 拡張機能:
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;
....
}
Web メソッドの SOAP 拡張機能:
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";
}
}