.net 调用启用 WS-Security 的 Web 服务(用 java 创建)

发布于 2024-08-18 19:27:18 字数 558 浏览 3 评论 0原文

如何使用 ws security 调用 Web 服务(用 java 创建),他们提供了证书文件、用户名和密码。密码,我尝试使用 Web 服务增强 (WSE) 3.0,从 Microsoft.Web.Services3.WebServicesClientProtocol 继承服务代理,使用用户名密码令牌时

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

How to call a webservice (created in java) with ws security, they provided a certificate file , username & password, i tried using Web Services Enhancements (WSE) 3.0, Inherited the service proxy from Microsoft.Web.Services3.WebServicesClientProtocol used username password tocken

  UsernameToken tocken = new UsernameToken("uname", "pwd");
  Service.RequestSoapContext.Security.Tokens.Add(tocken);

got error "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

Is it because of the client certificate ? I aslo tried

 X509Certificate xCert = new X509Certificate();
  xCert = X509Certificate.CreateFromCertFile("certificate_path.cer");
  Service.ClientCertificates.Add(xCert);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-08-25 19:27:18

我解决了这个问题,因为 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;
                }
            }

I solved the issue its becuase of ssl certificate validation problem, used

 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;
                }
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文