在C#中创建自定义绑定

998*_*823 6 c# asp.net wcf

我一直在尝试创建一个自定义绑定来输出这种类型的标头XML:

<soapenv:Header>
  <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
     <wsse:UsernameToken wsu:Id="UsernameToken-BEC9D84D8B68A3118D14543420311491">
        <wsse:Username>user</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hBcjVXk/NxiSiva5xXKphA==</wsse:Nonce>
        <wsu:Created>2016-02-01T15:53:51.146Z</wsu:Created>
     </wsse:UsernameToken>
  </wsse:Security>
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码:

        var customBinding= new CustomBinding();

        var securityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
        securityBindingElement.IncludeTimestamp = false;
        customBinding.Elements.Add(securityBindingElement);
        customBinding.Elements.Add(new TextMessageEncodingBindingElement());

        var transportElement = new HttpsTransportBindingElement();

        customBinding.Elements.Add(transportElement);
Run Code Online (Sandbox Code Playgroud)

但是我一直收到一条消息说:

The message could not be processed. This is most likely because the action is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings.

我很确定它与我的自定义绑定有关,但我正在努力弄清楚需要设置什么属性的时候非常困难.感谢任何指导!

The*_*ord 2

我认为客户端时间和服务器时间不匹配,至少错误看起来是这样的......

你能检查一下你的计时器吗?

如果我是对的,请参阅:如何:设置最大时钟偏差