ServicesResourcesConferencesOur TeamWeblogsAboutContact
   

Subscriptions

Post Categories

News

    MicrosoftBizTalkBlogs

Affiliations

Archives

Accessing the message inside of your WCF service operations

I have been asked this question many times and thought I just put a quick note here.
If you want to access the message from a WCF service operations then you need to distinguish two cases.

Strongly-typed contracts

public string Hello(string hello)
{
  Console.WriteLine(OperationContext.Current.RequestContext.RequestMessage.ToString());
           
  return hello;
}

Universal contracts

public void Process(Message message)
{
  Console.WriteLine(message.ToString());
}

But calling ToString() on the message itself will only print <stream>…</stream> if it is a streamed message.
In these cases you may need to do something similar like the following snippet in order to print the body of the streamed message.

XmlTextWriter xtw= new XmlTextWriter(Console.Out);
xtw.Formatting = Formatting.Indented;
message.WriteMessage(xtw);
writer.Flush();
writer.Close();



posted on Thursday, June 05, 2008 9:53 AM

# New and Notable 246 – SOA and WCF Edition @ Friday, June 06, 2008 2:31 PM

Along with my series , I have a New and Notable. I have pretty much abandoned N&amp;amp;N in favor of writing
Sam Gentile

# re: Accessing the message inside of your WCF service operations @ Saturday, June 28, 2008 10:44 PM

RequestContext.RequestMessage is not going to be present on one-way calls, so it's a partial solution at best. I've encountered this problem myself in the past, and ended up writing a message inspector for caching the messages: http://blogs.microsoft.co.il/blogs/sasha/archive/2008/06/15/obtaining-an-untyped-wcf-message-from-a-typed-service-operation.aspx
Sasha Goldshtein

# New and Notable 246 – SOA and WCF Edition @ Thursday, July 24, 2008 4:18 PM

Along with my series , I have a New and Notable. I have pretty much abandoned N&amp;amp;N in favor of writing
Sam Gentile The World According to MSCOREE


Powered by Community Server, by Telligent Systems