Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# .NET 4.0 WCF MessageSecurityException, "Security header is empty." when consuming a service

When using WCF and C# in a project I get an exception, MesssageSecurityException, with the message "Security header is empty.". Here follows the response (according to MS Service Trace Viewer):

    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <soapenv:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true"></wsse:Security>
        <wsa:Action>_WHAT_I_DID_</wsa:Action>
        <wsa:RelatesTo>_MSG_ID_OF_REQUEST_</wsa:RelatesTo>
      </soapenv:Header>
      <soapenv:Body>
        _CORRECT_BODY_
      </soapenv:Body>
    </soapenv:Envelope>

Indeed, the security header is "empty", but it is still correct accprding to the security header definition as far as I can tell.

I've also tried editing the bindings, but that doesn't seem to help as well. I also found a similar problem where enabling EnableUnsecuredResponse would help, but it doesn't here.

Here is the response according to SoapUI:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
      <wsa:Action>_WHAT_I_DID_</wsa:Action>
      <wsa:RelatesTo>_REQ_MSG_ID_</wsa:RelatesTo>
   </soapenv:Header>
   <soapenv:Body>
      _CORRECT_BODY_
   </soapenv:Body>
</soapenv:Envelope>

They are almost identical, except for how they close the security header. Which is interesting, but should not raise the exception?

I also found a similar problem where the solution was to create a custom message encoder and strip the entire security header, although this would work it is an extra unneeded step. Is that the only way to do it with .Net and WCF? Can't WCF handle security headers without content?

EDIT: Clarification of the issue, is writing an encoder which drops the security header the only way to recieve and parse SOAP-messages with empty security headers using WCF?

EDIT2: Adding part of conf:

    <binding name="NinjaBinding">
      <security allowSerializedSigningTokenOnReply="true" enableUnsecuredResponse="true"
      authenticationMode="UserNameOverTransport" requireDerivedKeys="false"
      securityHeaderLayout="Lax" includeTimestamp="false" allowInsecureTransport="true"
      keyEntropyMode="ClientEntropy"
      messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
      requireSecurityContextCancellation="false">
        <localServiceSettings detectReplays="false" />
        <secureConversationBootstrap _IDENTICAL_TO_ABOVE_
        </secureConversationBootstrap>
      </security>
      <textMessageEncoding />
      <httpsTransport />
    </binding>

As far as I know, its configure to allow practically everything?

like image 695
flindeberg Avatar asked Sep 06 '11 10:09

flindeberg


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

(Now I'm answering my own question since I've been able to elicit some kind of answer)

In short, no you cannot use WCF "out of the box" (ie through *.config) with application servers which provide empty security headers in responses. You have to implement an encoder which modifies messages to a format acceptable by the WCF-framework.

For more information read this blog which contains a quite good walkthrough of the encoder and its applications. This blog (another blog) also provides a code snippet capable of solving my issue, ie modifying the security header.

I wonder why MS and Oracle products never can co-exist peacefully :D

like image 177
flindeberg Avatar answered Nov 09 '22 09:11

flindeberg