Ask a questionAsk a question
 

AnswerSoap Header in WCF

Answers

All Replies

  • Thursday, July 13, 2006 3:17 PMRalph Squillace Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer

    Two main ways.

    • Contractually specified headers are done using the MessageHeaderAttribute for a MessageContractAttribute-created service.
    • Headers not part of the contract can be added to the headers properties of the OperationContext on either side. Outbound headers need to have a new OperationContextScope created in order to set the headers.

    Does this answer your question? Note that this model is different than the ASMX one. There is no attribute that you put on top of an operation to specify adding a specific header with a default value. Instead, if you care about headers you should create a MessageContractAttribute-based service contract, and then headers are directly part of the OM.

    Does this help?

    • Proposed As Answer bybeduin4 Thursday, April 23, 2009 10:41 AM
    •  
  • Thursday, July 13, 2006 6:12 PMScott Mason - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Here's a sample of the second method inside a Client MessageInspector.

    http://wcf.netfx3.com/files/folders/message_inspection/entry3783.aspx

    Thanks!

    S

  • Thursday, January 25, 2007 9:40 PMjdang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Scoot,

    I like the idea but it throws error when I try to run that sample.

    "Cross-thread operation not valid: Control 'txtRequest' accessed from a thread other than the thread it was created on."

    Regards,

    JDang

     

  • Thursday, January 25, 2007 9:46 PMjdang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Never mind.

    Thanks

  • Tuesday, January 30, 2007 4:41 PMjdang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Scott,

    I have tried to follow your example and I could not be able to see the message which sends from client to the server. The only different between your example and my example is I use app.config file. I think I may miss something on my App.Config file at <EndpointBehavior> attribute section. If you have to use app.config file then what you put on <EndpointBehavior>?

     

    Jdang

  • Friday, June 13, 2008 6:49 AMeyalp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Using this http://www.codeplex.com/WCFExtras you can write the following code:

     

    Code Snippet

    [SoapHeader("MyHeader", typeof(Header), Direction = SoapHeaderDirection.In)]
    [OperationContract]
    void SomeMethod();