2012-07-12 5 views
0

웹 서버에 전통적인 Xml 웹 서비스가 있습니다. Main Service.Overview 클래스 서비스가 아래에 나와 있습니다. 내 클라이언트에서null 값을 반환하는 ASP.Net xml 웹 서비스 속성

[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; 

변수 "키를"cording 한 나는 웹 서비스 클래스를 디버깅 암튼 액세스 할 때 null 값을 얻는 한 방법이있다. 개인 변수가 값을 가져오고있었습니다. 값이 클라이언트 코드에서 발생하지 않는 이유는 무엇입니까? 속성 값을 설정하지 않고 참조를 설정했을 수 있습니까? 웹 메서드를 통해 OUT 변수를 반환하여 변수 값에 액세스 할 수 있습니까? 아무도 답변을 설명해 주시겠습니까?

다음 방법을 사용하면 var key=mainService.symmetricKey;

를 사용하지만 symmetricKey이 byte[] 개인이고 그것의 contianing 유형 외부에 액세스 할 수 없습니다 키를 사용하면 클라이언트 코드에서

[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; 
     } 
    } 
+0

클라이언트에서 대명사에 대문자를 잘못 사용하고 있습니다. SymmetricKey – HatSoft

+0

죄송합니다. 질문을 게시하는 것은 저의 실수였습니다. 지금 편집했습니다. 실제 코드는 귀하가 말한 것과 같습니다. – Thabo

+0

서비스에 코드를 표시 할 수 있습니까? SymmetricKey가 할당 된 값을 얻는 방법 – HatSoft

답변

1

을 생성 된 웹 방법이다.

나는 원인이 의심 라인은 문제가이 일

 SymmetricKey = rijndaelManaged.Key; 

CreateKeys 방법 내부의 catch 블록해야합니다 : 그래서 당신이

var key=mainService.SymmetricKey; 

업데이트처럼 public property SymmetricKey을 사용해야합니다 던져서 예외를 일으키다;

+0

죄송합니다. 질문을 게시하는 것이 저의 실수였습니다. 지금 편집했습니다. 실제 코드는 귀하가 말한 것과 같습니다. – Thabo

+0

CreateKeys 메서드의 catch 블록에 중단 점을 넣고 catch 오류가 있는지 확인하십시오. – HatSoft

관련 문제