我在我的web服務器上有一個傳統的xml web服務。它有一個服務調用Main Service。Class的概述如下。ASP.Net xml web服務屬性返回空值
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// [System.Web.Script.Services.ScriptService]
public class MainService : System.Web.Services.WebService
{
private byte[] symmetricKey;
private byte[] symmetricIv;
public byte[] SymmetricKey
{
get { return symmetricKey; }
set { symmetricKey = value; }
}
public byte[] SymmetricIv
{
get { return symmetricIv; }
set { symmetricIv = value; }
}
//Constructor
public MainService()
{
this.GetDatabaseInstance();
}
//Some Web Methods Heare to create the Symmetric Key
}
在我的客戶,我有一個方法,在那裏我有以下盤帶
MainService mainService=new MainsService();
//Calling to Some web method to create symmetric keys and assign those properties
//Now trying to access those properties
var key=mainService.SymmetricKey;
變量「鑰匙」是越來越空值,當我訪問that.But我調試Web服務類。私有變量正在獲取值。爲什麼值沒有出現在客戶端代碼中?可能是屬性是設置引用而沒有設置值?因爲我可以通過web方法返回OUT變量來訪問變量值?任何人都可以解釋答案嗎?
以下方法是Web方法,它是創建密鑰
[WebMethod]
//create a symmetric key and encript it using clients public key and return values
public bool CreateKeys(byte[] exponent, byte[] modulus)
{
try
{
//Create a new instance of the RSACryptoServiceProvider class.
var rsaCryptoServiceProvider = new RSACryptoServiceProvider();
//Create a new instance of the RSAParameters structure.
RSAParameters rsaKeyInfo = new RSAParameters();
//Set RSAKeyInfo to the public key values.
rsaKeyInfo.Modulus = modulus;
rsaKeyInfo.Exponent = exponent;
//Import key parameters into RSA.
rsaCryptoServiceProvider.ImportParameters(rsaKeyInfo);
//Create a new instance of the RijndaelManaged class.
var rijndaelManaged = new RijndaelManaged();
rijndaelManaged.GenerateKey();
rijndaelManaged.GenerateIV();
//save the symmetric key and IV
SymmetricKey = rijndaelManaged.Key;
SymmetricIv = rijndaelManaged.IV;
//Encrypt the symmetric key and IV.
encryptedSymmetricKey = rsaCryptoServiceProvider.Encrypt(rijndaelManaged.Key, false);
encryptedSymmetricIv = rsaCryptoServiceProvider.Encrypt(rijndaelManaged.IV, false);
return true;
}
catch (Exception)
{
throw;
}
}
在你的客戶端你正在使用錯誤的情況下proeprty它應該是SymmetricKey – HatSoft 2012-07-12 18:02:57
對不起,這是我的錯誤發佈question.I編輯now.Actual代碼就像你說的。 – Thabo 2012-07-12 18:15:17
請你可以在你的服務中顯示代碼SymmetricKey如何得到它的值 – HatSoft 2012-07-12 18:16:07