locked
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

    http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP
    http://kjellsj.blogspot.in/2007/02/wcf-streaming-upload-files-over-http.html
    http://stefanoricciardi.com/2009/08/28/file-transfer-with-wcp/

    Sunday, March 31, 2013 1:53 AM

Answers

  • User-1662538993 posted

    Here is the details for why we use MessageContract -

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

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/ccbf6cb3-23dd-4e95-86a2-4ecdd390f9b1/

    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