TheWommies
TheWommies

Reputation: 5072

Using WCF Message

I am still confused when it is appropriate to use the Message type in WCF like below

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    Message GetData();

    [OperationContract]
    void PutData(Message m);
}

Why would you want to use it?

Can you use it for streaming?

Thanks

Upvotes: 2

Views: 243

Answers (2)

np-hard
np-hard

Reputation: 5815

While the reasons listed by Tim are valid, we use messages directly in our services to create one uber routing service. we have one service that can take any method call you throw at it, Clients are generated by wsdls supplied from multiple sources.

This service would take the message, examine its content and route it accordingly. So in my opinion if you want to get closer to the wire, or when you dont know the type of incoming messages, you can use the message in the signature directly.

Streaming is a separate concept than message signature, streaming is supported by wcf under very specific bindings and security mechanism and the method signature has to be very specific (i.e it should return/accept stream). Also in streaming the actual stream of data travels outside the scope of soap message.

Upvotes: 3

Tim
Tim

Reputation: 28520

MSDN lists the follow reasons for using the message class directly:

  1. When you need an alternative way of creating outgoing message contents (for example, creating a message directly from a file on disk) instead of serializing .NET Framework objects.

  2. When you need an alternative way of using incoming message contents (for example, when you want to apply an XSLT transformation to the raw XML contents) instead of deserializing into .NET Framework objects.

  3. When you need to deal with messages in a general way regardless of message contents (for example, when routing or forwarding messages when building a router, load-balancer, or a publish-subscribe system).

See Using the Message Class for more detailed information.

Edit to address the streaming question

I didn't find a definitive answer in my quick scan via google, but the article above states "All communication between clients and services ultimately results in Message instances being sent and received" - so I would assume it could be used directly in streaming.

Upvotes: 4

Related Questions