正在使用J2EE Web服务签名请求,但收到未签名的响应

问题描述 投票:0回答:1

我正在使用第三方J2EE Web服务,该服务需要使用证书对请求进行签名,但是该Web服务正在响应未签名的响应。

这是我执行请求的方式:

    public static WcfServiceNamespace.ResponseType GetResponse(X509Certificate2 certificate)
    {
        var request = GetExampleRequest();
        var endPoint = new EndpointAddress($"https://endPoint.url/contoso");
        var binding = GetCustomBinding();

        ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
        using (var client = new WcfServiceNamespace.ServicePortTypeClient(binding, endPoint))
        {
            client.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
            client.ClientCredentials.ClientCertificate.Certificate = certificate;
            return client.ProcessRequest(request);
        }
    }

    private static Binding GetCustomBinding()
    {
        var c = new CustomBinding();
        var version = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        var sec = SecurityBindingElement.CreateCertificateOverTransportBindingElement(version);
        sec.EnableUnsecuredResponse = true;
        sec.AllowInsecureTransport = true;
        sec.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
        c.Elements.Add(sec);
        c.Elements.Add(new TextMessageEncodingBindingElement() {MessageVersion = MessageVersion.Soap11});
        c.Elements.Add(new HttpsTransportBindingElement() { RequireClientCertificate = true });
        return c;
    }

Java Web服务正确响应了没有任何标头的请求:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
       <!-- correct response -->
       </soapenv:Body>
    </soapenv:Envelope>

并且WCF客户端在尝试处理响应时抛出异常:

    System.ServiceModel.Security.MessageSecurityException: 'Cannot find a token authenticator for the 'System.IdentityModel.Tokens.X509SecurityToken' token type. Tokens of that type cannot be accepted according to current security settings.'

我已经尝试过此配置:WCF - Cannot find a token authenticator for X509SecurityToken但这不能解决我的问题,因为响应的标头完全为空,如我之前所述,并且端点使用的是https,但没有可信任的证书。

有什么方法可以配置WCF来正确签署请求但忽略响应安全性?

编辑:我已经试过这个问题:

但是答案无济于事

c# web-services wcf wcf-binding wcf-security
1个回答
0
投票

我们可以使用下面的工具来生成SOAP客户端,通过它我们可以像下面的方法那样提供服务?https://docs.microsoft.com/en-us/dotnet/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe它是Visual Studio中的内置工具,我们可以使用SVCUtil命令生成客户端代理类以及兼容的自定义绑定和安全模式配置。实例化时,客户端代理将自动使用与服务器兼容的配置来创建请求。或者,我们可以通过“添加服务参考”菜单生成客户端代理。https://docs.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client我从未致电过J2EE Web服务,请告诉我它是否有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.