2015-11-13 122 views
0

我試圖從客戶端發送XML到服務器。我使用這個using System.Security.Cryptography.X509Certificates;並得到AuthenticateClient中的異常。唯一的例外是服務器(java)無法從客戶端(c#)使用SSL連接接收XML

AutenticationException被抓,到SSPI調用失敗,請參見內部 例外。

這是我的代碼:

public static SslStream OpenSSL(string _IP, int _port) 
{ 
    try 
    { 
     TcpClient client = new TcpClient(_IP, _port); 

     // Create a secure stream 
     SslStream sslStream = new SslStream(client.GetStream(), false, 
        new RemoteCertificateValidationCallback(ValidateServerCertificate), null); 

     if (sslStream != null) 
     { 
      sslStream.AuthenticateAsClient(_IP); 
     } 

     return sslStream; 
    } 
    catch (Exception _e) 
    { 
     Util.Log.Track(Config.System.LogMode.UTIL, "Comms.Handler.OpenSSL: exception = " + _e.ToString()); 
     return null; 
    } 
} 

我可以連接到服務器,但是服務器將不會收到XML。我被困在這裏2天了,有人知道這個問題有什麼問題嗎?

:我用VS2010(客戶端)和Eclipse火星的Linux操作系統(服務器)

回答

0

嘗試添加此C#代碼

System.Net.ServicePointManager.ServerCertificateValidationCallback = 
    ((sender, certificate, chain, sslPolicyErrors) => true); 

它忽略SSL驗證的錯誤

然後嘗試另一種方法 更改它

if (sslStream != null) 
{ 
    sslStream.AuthenticateAsClient(_IP); 
} 

這個

X509Certificates.X509Certificate2Collection xc = new X509Certificates.X509Certificate2Collection(); 
sslStream.AuthenticateAsClient(_IP, xc, Security.Authentication.SslProtocols.Tls, false); 

其實,我不知道SslProtocols標誌。也許SslProtocols.Tls | SslProtocols.Ssl3

如果沒有幫助,我沒有任何想法:)

+0

謝謝回答。但它不起作用,服務器仍然沒有收到XML – Mirza

+0

嘗試另一種方法 –

相關問題