0

i want a web application to create a service reference to my WCF service, insert information to the header of the soap call and call my WCF method.

i read about MessageContract attribute and declared one in the interface file:

[MessageContract]
public class BasicServiceHeader
{
    [MessageHeader]
    public string myString;
}

my WCf interface is:

   [ServiceContract]
public interface IBasicService
{

    [OperationContract]       
    [WebGet(UriTemplate = "GetData?value={value}")]     // Add support for HTTP GET Requests
    string GetData(int value);}

i don't want the BasicServiceHeader to be passed as a parameter of GetData function , i want to keep the function as it is and to extract the BasicServiceHeader inside the function, can i do that ?

Rodniko
  • 4,926
  • 20
  • 69
  • 93

1 Answers1

0

Client side, you can pass a header prior invoking the operation:

MessageHeader messageHeader = MessageHeader.CreateHeader(_headerName, _headersNameSpace, _headerValue);
OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

and extract it using FindHeader service side

vc 74
  • 37,131
  • 7
  • 73
  • 89
  • thank you, but i don't think my client has Framework 3.5. he works in the 'asmx way' , how can my client add a new header information to the soap method call in Framework 2.0? – Rodniko Sep 17 '10 at 11:11
  • Ah OK, does this help? http://blogs.msdn.com/b/kaevans/archive/2007/08/06/programmatically-insert-soapheader-into-soap-request-with-asmx-soapextensions.aspx – vc 74 Sep 17 '10 at 11:36
  • Before i get inside Soapextensions which seems as a very complex subject, can you tell me if WCF supports the SoapHeader attribute?. i found a simple example of using SoapHeader: http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapheader.aspx , but i can't get it to work. – Rodniko Sep 17 '10 at 12:00
  • 1
    I don't think so but it supports the method I wrote earlier (using the OutgoingMessageHeaders property) – vc 74 Sep 17 '10 at 12:53