locked
Message Contract in WCF RRS feed

  • Question

  • Hi,

    In what kind of situation we should go for Message Contract in WCF service? What are the data contract limitations those have been addressed  by Message Contract?

    Thanks in advance.

    Regards

    ronit_rc

    Thursday, October 6, 2011 2:11 PM

Answers

  • Hi,

    Thanks! Somewhere I have seen "MessageContract enables you to interoperate with any system that communicates through SOAP". Can I get some example of those kind of System? Moreover, while using DataContract then also we are communicating through SOAP. So what the big deal in MessageContarct as per as communication is concerned?

    regards

    ronit_rc

    • Marked as answer by ronit_rc Thursday, November 17, 2011 8:25 AM
    Monday, October 31, 2011 6:57 PM

All replies

  • One of the most common scenario for using MessageContracts is for custom authentication and authorization. The message is packed with authentication/authorization information at the client side in the MessageHeader, in an out of band way, using a MessageInspector. The Service intercepts this message, and works out the authentication/authorization by taking the data out of the MessageHeader.

    This way you can also pack in some context information to the service calls, which you think you don't want to include in every client call, but want it to packed in the message everytime.

    Thursday, October 6, 2011 2:16 PM
  • Hi saurabh,

    Thanks for the answer. As per my understanding I can allways pack something in MessageHeader from client without using MessageContract. In fact I have implemented Message level security using the same. I am still unable to understand what is the real use of Message Contract over Data Contracts? If you could provide an example that will be helpfull for me.

    Regards

    ronit_rc

    Thursday, October 6, 2011 3:15 PM
  • It is much neater to pack information into headers and the overall SOAP message using MessageContracts.

     

    Refer this and this for more insights.

    Thursday, October 6, 2011 4:38 PM
  • Say our message goes through several hopes between several WS-s in our composite application. We route the message with some address information which changed in each hope. We have to place somewhere this address info. It can be inside message (which is unlikely) and in the header of this message.

    So, placing variable information or routing information into the header gives us a lot of flexibility and will not change anything in the message body.


    Leonid Ganeline [BizTalk MVP] BizTalk: Sample: Context Routing and Throttling with orchestration
    Thursday, October 6, 2011 4:46 PM
  • Hi Leonid,

    Thanks! Could you bit explain a bit? Like what are the hopes? Should we use Message Contract in case of Routing?

    Moreover what advantage I am achieving on putting it in header?

    Regards

    ronit_rc

    Thursday, October 6, 2011 4:58 PM
  • DataContracts are used to descibe the data types used by a service. This enables the types to be described in metadata to enable clients to interop with the service. DataContracts can be used to describe either parameters or return values. DataContracts are unnecessary if the service only uses simple types.

    1. DataContracts descibes the datatypes used by a service.
    2. DataContracts can be used to describe either parameters or return values.
    3. DataContracts are unnecessary if the service only uses simple types
    4. Data contracts enable interoperability through the XML Schema Definition (XSD) standard

    While, MessageContract(s) describes the structure of SOAP messages(since SOAP is context oriented - passing-on complete information about object) sent to/from a service and enable you to inspect and control most of the details in the SOAP header and body.

    1. Generic - MessageContract enables you to interoperate with any system that communicates through SOAP.
    2. Control - Using message contracts, we get complete control over SOAP messages sent to/from a service by having access to the SOAP headers and bodies.
    3. Object Context - This(SOAPing) allows use of simple or complex types to define the exact content of the SOAP.

    DataContract deals with XML,Message Contract deals with SOAP.

    Whether you need to use either of these depends on your scenario to use it on XML or SOAP.

     


    Lingaraj Mishra
    Thursday, October 6, 2011 5:12 PM
  • Hi,

    As per my understanding, even if I use Data Contracts the type defined in it will serialize in XML and will transmit over wire as a part of SOAP body. So in communication message format  is allways  SOAP in both cases(Message Contract/Data Contract). Are you pointing about the fact that in case of Message Contract no XML serialization happens?

    regards

    ronit_rc

    Thursday, October 6, 2011 5:35 PM
  • XML serialization will happen in both the cases.
    Thursday, October 6, 2011 6:07 PM
  • Hi Saurabh,

    Could you please provide me an example/Sample where a WCF Message Contract is used in order to communicate through SOAP?

    Thanks in advance.

    Regards

    ronit_rc

     


    • Edited by ronit_rc Sunday, October 9, 2011 5:30 AM
    Sunday, October 9, 2011 5:30 AM
  • Hi,

    Also I have heard Message contract is used for bypassing WS(*). How it bypasses WS standards?

    Regards

    ronit_rc

    Sunday, October 16, 2011 4:39 AM
  • Hi Leonid,

    Thanks! Could you bit explain a bit? Like what are the hopes? Should we use Message Contract in case of Routing?

    Moreover what advantage I am achieving on putting it in header?

    Regards

    ronit_rc


    Hopes are the itinerary steps. Message could be transmitted from one router to another on the way to requester in many steps - hopes.

    Headers used to place an additional information to the message. Message is a document, a data which has a business meaning. If we need to send an additional information which is not the business inf, but some additional infractucture information, SOAP has a special mechanism - the headers. If we need some control of this information we should use the message contract. If we don't want to deal with this information and want to let the infrastructure deals with it, we don't need it. Say we want to manage the login/passwords/.. (authentification), we need Headers hence we need the Message Contract.

    So in your case using Message Contract will not do any help. Use the DataContracts.


    Leonid Ganeline [BizTalk MVP] BizTalk: Sample: Context Routing and Throttling with orchestration
    Sunday, October 30, 2011 10:29 PM
  • Hi,

    Thanks! Somewhere I have seen "MessageContract enables you to interoperate with any system that communicates through SOAP". Can I get some example of those kind of System? Moreover, while using DataContract then also we are communicating through SOAP. So what the big deal in MessageContarct as per as communication is concerned?

    regards

    ronit_rc

    • Marked as answer by ronit_rc Thursday, November 17, 2011 8:25 AM
    Monday, October 31, 2011 6:57 PM