在C#中创建自定义绑定

时间:2016-03-14 14:47:01

标签: 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>

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

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

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

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

我很确定它与我的自定义绑定有关,但是我很难找到需要设置的属性。感谢任何指导!!!

1 个答案:

答案 0 :(得分:2)

我认为客户端时间和服务器时间不匹配,至少错误似乎是......

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

如果我是对的,请看:How to: Set a Max Clock Skew