Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Custom Binding in C#

Tags:

c#

asp.net

wcf

I've been trying to create a custom binding to output this type of header 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>

Here is my code so far:

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

However I keep receiving a message stating:

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.

I'm pretty certain it has to do with my custombinding but i'm having a terribly difficult time trying to figure out what properties need set to what. Appreciate any guidance!!!

like image 545
99823 Avatar asked Mar 14 '16 14:03

99823


1 Answers

I think that the client time and the server time are mismatching, at least the error seems like it...

Could you check your timers?

If i'm right see this: How to: Set a Max Clock Skew

like image 176
TheCodeLord Avatar answered Oct 23 '22 14:10

TheCodeLord