如何使用ws security调用web服务(在java中创建),他们提供了一个证书文件,用户名&密码,我尝试使用Web服务增强功能(WSE)3.0,从Microsoft.Web.Services3.WebServicesClientProtocol继承服务代理使用用户名密码tocken
UsernameToken tocken = new UsernameToken("uname", "pwd");
Service.RequestSoapContext.Security.Tokens.Add(tocken);
收到错误“基础连接已关闭:无法为SSL / TLS安全通道建立信任关系。”
是否因为客户证书?我也试过了
X509Certificate xCert = new X509Certificate();
xCert = X509Certificate.CreateFromCertFile("certificate_path.cer");
Service.ClientCertificates.Add(xCert);
答案 0 :(得分:0)
我解决了问题,因为使用了ssl证书验证问题
UsernameToken token = new UsernameToken("uname", "pwd", PasswordOption.SendPlainText);
Service.RequestSoapContext.Security.Tokens.Add(token);
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy()
{ }
public bool CheckValidationResult(ServicePoint sp,
X509Certificate cert, WebRequest req, int problem)
{
return true;
}
}