【问题标题】:Remove Timestamp from WSSE Security Header C# ASMX/WCF Service从 WSSE 安全标头 C# ASMX/WCF 服务中删除时间戳
【发布时间】:2017-08-10 02:11:45
【问题描述】:

我在我的项目中添加了一个 Java WSDL 作为 Web 参考。我正在使用它来调用端点上的服务。我在 ASMX 文件中添加了一个 WebMethod 并在那里调用该服务。要求是使用 WSE 安全并使用 X509 证书签署请求。

不幸的是,时间戳产生了问题,我收到了响应“处理标头时发现错误”。如果我从中删除 TimeStamp 元素,SoapUI 中的相同请求将起作用。 This is how the request look like

这是创建安全元素的代码

  //Set WSSE Security
  svc.RequestSoapContext.Security.Timestamp.TtlInSeconds = 300;
  svc.RequestSoapContext.Security.MustUnderstand = true;
  svc.RequestSoapContext.Security.Tokens.Add(newtoken);
  Microsoft.Web.Services3.Security.MessageSignature signature = new Microsoft.Web.Services3.Security.MessageSignature(newtoken);
  signature.SignatureOptions = Microsoft.Web.Services3.Security.SignatureOptions.IncludeSoapBody;            
  svc.RequestSoapContext.Security.Elements.Add(signature);

================

使用 WCF

即使我使用 WCF 执行此操作,问题仍然存在。只要我添加 IncludeTimestamp = false;请求未发送,将其设置为 true 可以创建请求。

这是 WCF 代码 -

        //Create Endpoint
        EndpointAddress address = new EndpointAddress((istest == true ? CHORUS_UFB_EMMA : CHORUS_UFB_PROD));

        //Add Certificate to EndPoint Service
        X509Certificate2 cert = new X509Certificate2(@"Certificate Path", "Password", X509KeyStorageFlags.PersistKeySet);

        //Setup custom binding with HTTPS + Body Signing + Soap1.1
        CustomBinding binding = new CustomBinding();

        //HTTPS Transport
        HttpsTransportBindingElement transport = new HttpsTransportBindingElement();

        //Set Security Binding as Transport
        TransportSecurityBindingElement tsec = SecurityBindingElement.CreateCertificateOverTransportBindingElement(MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConvers‌​ation13WSSecurityPol‌​icy12BasicSecurityPr‌​ofile10);
        tsec.EnableUnsecuredResponse = true;
        tsec.AllowInsecureTransport = true;
        tsec.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
        tsec.LocalServiceSettings.DetectReplays = false;
        tsec.LocalClientSettings.DetectReplays = false;
        tsec.IncludeTimestamp = false;
        tsec.SetKeyDerivation(false);
        tsec.EndpointSupportingTokenParameters.Signed.Add(new SecureConversationSecurityTokenParameters());

        //Setup for SOAP 11 and UTF8 Encoding
        TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);

        //Bind in order (Security layer, message layer, transport layer)
        binding.Elements.Add(tsec);
        binding.Elements.Add(textMessageEncoding);
        binding.Elements.Add(transport);

Here is the generated request using above code 对此的任何帮助将不胜感激。

【问题讨论】:

    标签: c# web-services wcf soap wsse


    【解决方案1】:

    这可能是由于您的客户端与托管您调用的服务的 Web 服务器之间的时间差异造成的。

    仔细检查两台服务器上的时间是否匹配且同步。时间可能需要在 5 分钟以内。

    【讨论】:

      猜你喜欢
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      相关资源
      最近更新 更多