How to transfer objects through the header in WCF

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-03-31T09:04:27Z Indexed on 2010/03/31 14:23 UTC
Read the original article Hit count: 448

Filed under:
|

I'm trying to transfer some user information in the header of the message through message inspectors.

I have created a behavior which adds the inspector to the service (both client and server).

But when I try to communicate with the service I get the following error:

XmlException:
Name cannot begin with the '<' character, hexadecimal value 0x3C.

I have also get exception telling me that DataContracts where unexpected.

Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

The thing is that my object contains other objects which are marked as DataContract and I'm not interested adding the KnownType attribute for those types.

Another problem might be that my object to serialize is very restricted in form of internal class and internal properties etc.

Can anyone guide me in the right direction. What I'm I doing wrong?

Some code:

public virtual object BeforeSendRequest(ref Message request, IClientChannel channel)
{
    var header = MessageHeader.CreateHeader("<name>", "<namespace>", object);
    request.Headers.Add(header);

    return Guid.NewGuid();
}

© Stack Overflow or respective owner

Related posts about wcf

Related posts about c#4.0