locked
Data Contract or Message Contract in WCF? RRS feed

  • Question

  • User-1623675128 posted

    Hi new to WCF world but familiar with ASMX.

    I have a situation here like..

    Need a WCF service which takes a input and perform some actions based on the input data like get the files and store it in a location for another service.

    input will have several paramters like file name, size, location, etc but the point is this WCF will be used in classic ASP as well along with other .NET apps.

    So, I am thinkning should I go with Message contract or Data contract. and how about bindings should it be differebnt based on contract?

    or will it be possible without any contract as just passing XML as a paramter to operation contract like ASMX web method? [I like this bcoz of classic asp clients eixsts]

     

    Thursday, October 24, 2013 7:30 AM

Answers

  • User-484054684 posted

    You are welcome, Ram.

    Yes. We need to define an OperationContract that can accept an object (just like normal methods).

    This can then be consumed by clients in two ways:

    1. Use proxy, fill the objects and call as if it is a normal method. (But on the background, dotnet will convert the object to xml for processing)

    2. We can simply construct the plain xml and send it as a HttpRequest. I've not tried this option but can be done.it wo

    Prefer the 1st option, as it would be easier to construct the objects than the xml manually.

    Please let me know if any other questions. Suggest to go through some How-To articles on WCF to understand this still better.

    Please mark this as answer if this answers your question.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 25, 2013 5:58 AM

All replies

  • User-484054684 posted

    Based on your requirement, I think, the best suitable option for you is to use - basicHttpBinding,

    It will have input as xml and gives response also in xml - you can observe it if you enable tracing. i.e., it will accept the objects as the input but under the hood, it will be converted to xmls.

    How to create WCF service to use basicHttpBinding? - Refer this link http://msdn.microsoft.com/en-us/library/ff648505.aspx
    Note: You may not need Step 3 and Step 4 in that article.

    Also, DataContract would be simpler to use, instead of MessageContracts. We need to use MessageContract only when we want to incorporate certain SOAP similar futures in our service. Refer the link: http://www.sujitbhujbal.com/2012/05/when-to-use-data-contract-and-message.html

    Please mark this as answer if this answers your question.

    Thursday, October 24, 2013 8:44 AM
  • User-1623675128 posted

    Thanks Siva for the response.

    you mean define Operation contract which  takes input as string paramter and send XML in it as a input? pls clarify.

    Also, what if we need to later add authentication into this service as username and pwd sort of?

    Friday, October 25, 2013 12:27 AM
  • User-484054684 posted

    You are welcome, Ram.

    Yes. We need to define an OperationContract that can accept an object (just like normal methods).

    This can then be consumed by clients in two ways:

    1. Use proxy, fill the objects and call as if it is a normal method. (But on the background, dotnet will convert the object to xml for processing)

    2. We can simply construct the plain xml and send it as a HttpRequest. I've not tried this option but can be done.it wo

    Prefer the 1st option, as it would be easier to construct the objects than the xml manually.

    Please let me know if any other questions. Suggest to go through some How-To articles on WCF to understand this still better.

    Please mark this as answer if this answers your question.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 25, 2013 5:58 AM
  • User-1623675128 posted

    Thanks I did it with Message Contract so that I was able to send the required authentication info as well in request from clients..

    Monday, October 28, 2013 12:16 AM