WCF file upload functionality and message contract usage RRS feed

  • Question

  • User88744855 posted

    i am new in WCF. once i was searching code for uploading file to web server by wcf. i found a code which uses message contract for file details. i just do not understand why people use message contract. according to that situation the coder can use data contract only instead of message contract....so why they used message contract is not clear.
    here is the link of source code for file upload by wcf. just have a look and tell me can we use data contract for file information instead of message contract. give some few good situation when one has to use message contract instead of data contract. thanks
    these are the link


    Sunday, March 31, 2013 1:53 AM


  • User-1662538993 posted

    Here is the details for why we use MessageContract -

    Please check this thread from where i have copy pasted it below:


    Data Contracts:

    WCF data contracts provide a mapping function between .NET CLR types that are defined in code and XML Schemas Definitions defined by the W3C organization (www.w3c.org/) that are used for communication outside
    the service.

    Message Contracts:

    Message contracts describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body. Whereas data contracts enable interoperability through the XML Schema Definition (XSD) standard, message contracts enable you to interoperate with any system that communicates through SOAP. Using message contracts gives you complete control over the SOAP message sent to and from a service by providing access to the SOAP headers and bodies directly. This allows use of simple or complex types to define the exact content of the SOAP parts.

    The example you have posted use message header to pass information to the client and hence uses message contract. You can use data contract as well just for the purpose of file upload function.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 1, 2013 8:55 AM