C# 正在使用J2EE web服务签名请求但接收未签名的响应

C# 正在使用J2EE web服务签名请求但接收未签名的响应,c#,web-services,wcf,wcf-binding,wcf-security,C#,Web Services,Wcf,Wcf Binding,Wcf Security,我正在使用第三方J2EE web服务,该服务要求使用证书对请求进行签名,但web服务正在响应未签名的响应 这就是我处理请求的方式: public static WcfServiceNamespace.ResponseType GetResponse(X509Certificate2 certificate) { var request = GetExampleRequest(); var endPoint = new EndpointAddress

我正在使用第三方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>
我已经尝试过此配置: 但它并没有解决我的问题,因为响应的头是完全空的,正如我前面解释的,并且端点使用https,但没有可信任的证书

我的问题是: 有没有办法将WCF配置为正确签署请求,但忽略响应安全性

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

但答案没有帮助

编辑:
我让它与WSE3一起工作,但我想使用一种更新的技术。如果它在WSE3中工作,为什么不在WCF中工作?

我们可以使用下面的工具来生成SOAP客户端,通过它我们可以像下面的方法一样调用服务吗?

它是Visual Studio中的内置工具,我们可以使用
SVCUtil
命令生成客户端代理类和兼容的自定义绑定和安全模式配置。在实例化时,客户端代理将自动使用与服务器兼容的配置来创建请求。
或者,我们可以通过添加服务参考菜单生成客户端代理。


我从未调用过J2EE web服务,请让我知道它是否有用。

可能重复我已经尝试过,但它无法解决我的问题,因为响应的标题完全为空,正如我之前解释的,并且端点使用https,但没有可信任的证书。这没有帮助,我已经知道svcuti.exe命令。它以与“添加服务”类似的方式生成代理类和配置文件,问题在于服务的配置。svcutil命令未检测到安全配置,它检测到basicHttpBinding和常用终结点。该命令能否成功完成?就像下面的表格。Svcutil.exe/d:d:\我想知道自动生成的configuration.output.config内容:如果我们通过在Asp.net项目中添加服务引用来调用服务,它也会生成相同的配置,是吗?如果我们生成客户机代理,然后调用服务方法,会发生什么,如下所示。Servicereference1.serviceclient客户端=新的Servicereference1.serviceclient();请尝试{var result=Client.test();}catch(Exception){throw;}此外,据我所知,在WCF中,使用证书验证客户机的basichttpbinding要求客户机提供一个证书来签署SOAP消息。因此,我们可以使用ChannelFactory配置以下绑定类型来与服务器通信吗?
    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.'