我試圖消耗第三方Web服務(在俄語語言詳細描述)https://92.46.122.150:8443/esf-web/ws/SessionService?wsdl如何在Visual Studio中將Soap Header傳遞給SOAP WCF服務?
我試圖連接到使用方法「了createSession」網站,獲得一個網站ID會話和關閉會話。 做到這一點我使用Visual Studio 2013,C#,.NET 4.5,WSE 3.0(Microsoft.Web.Services3.dll)。
我已經在Visual Studio 2013「Windows窗體應用程序」中創建了項目。在這種形式下,用戶可以輸入用戶名,登錄名和選擇他的數字簽名證書。此外,我將Web服務添加爲「Web服務參考」,但我不確定如何傳遞標頭的憑據。
我試圖做到這一點:
string strPasswordCertificate = "123456";
string strCertificate = "C:/Test/AUTH_RSA_db79bb07b4722c042e025979b3b11995fc46765b.p12";
X509Certificate x509_CertAUTH = new X509Certificate(strCertificateFilePathAUTH, strPasswordCertificate);
string strCertAUTH = x509_CertAUTH.ToString();
CreateSessionRequest CreateReq = new CreateSessionRequest();
CreateReq.x509Certificate = strCertAUTH;
string strIIN = "753159846249";
CreateReq.tin = strIIN;
WS.createSession(CreateReq);
但運行時PROGRAMM的Visual Studio顯示上線錯誤 「WS.createSession(CreateReq)」 象下面這樣:
SoapHeaderException未處理。 System.Web.Services.dll中發生未經處理的「System.Web.Service.Protocols.SoapHeaderExeption」類型異常 附加信息:處理「wsse:Security」標頭時發現錯誤。
當通過SOAP調用XML Web服務方法並在處理SOAP標頭期間發生異常時引發此異常。 之後,我在我的代碼所做的更改如下圖所示:
string strPasswordCertificate = "123456";
string strCertificate = "C:/Test/AUTH_RSA_db79bb07b4722c042e025979b3b11995fc46765b.p12";
X509Certificate x509_CertAUTH = new X509Certificate(strCertificateFilePathAUTH, strPasswordCertificate);
string strCertAUTH = x509_CertAUTH.ToString();
CreateSessionRequest CreateReq = new CreateSessionRequest();
CreateReq.x509Certificate = strCertAUTH;
string strIIN = "753159846249";
CreateReq.tin = strIIN;
WS.createSession(CreateReq);
string _userName = "123456789011";
string _UserPassword = "TestPass123";
UsernameToken userToken;
userToken = new UsernameToken(_userName, _UserPassword, PasswordOption.SendPlainText);
SessionService WS = new SessionService();
SoapContext requestContext = WS.RequestSoapContext;
requestContext.Security.Tokens.Add(userToken);
WS.createSession(CreateReq);
但隨着運行線路上的PROGRAMM Visual Studio中顯示錯誤時,「WS.createSession(CreateReq)」象下面這樣:
SoapHeaderException是未處理。 System.Web.Services.dll中發生未經處理的「System.Web.Service.Protocols.SoapHeaderExeption」類型異常 附加信息:提供了無效的安全令牌。
我需要更多的工作或改變我的代碼,web崇敬開始工作?任何想法?