Last post Oct 15, 2012 12:04 PM by dotnetterAMG123
Oct 07, 2012 05:43 PM|dotnetterAMG123|LINK
Hello - I'm on a project where WCF services have been implemented using a request/response pattern. For example, a client would submit a GetUserRequest object and the system would return a GetUserResponse object.
Based on general googling, it appears that a lot of people recommend using MessageContracts when you need control over the format of the data returned. For example, DataContracts have a default output like
But I should be able to implement a MessageContract to return the data in the following format:
<Name first="John" last="Smith">
However, it seems like it may be logical to use MessageContracts as a general wrapper when implementing a request/response pattern. This would give you the flexibility to include different types of data in the response without tightly coupling different
types of data into a single structure.
For example, I could create a GetUserResponse MessageContract that included a User DataContract as a MessageMember as well as an int ReturnCode MessageMember as an additional indicator. This would avoid tightly coupling a return code with actual system data.
So is this a fairly commmon implementation of MessageContracts in WCF?
Oct 08, 2012 09:16 AM|kushalrdalal|LINK
You can achieve this without using MessgaeContract.
Create two custom object GetUserRequest and GetUserResponse and add necessary properties like User and Id and FirstName.
If you want more than one user then create user class and then add this properties to that class in and in GetUserResponse have List<User>.
Just create normal method and return type of GetUserResponse and argument of GetUserRequest.
Something like this -
public GetUserResponse GeoUserResponsetTest(GetUserRequest getUserRequest )
Oct 15, 2012 12:04 PM|dotnetterAMG123|LINK
I realized another good reason to always use message contracts for enterprise WCF services.
WCF implements rules such that only 1 MessageContract can be passed as a request. WCF also implements rules such that if a MessageContract is passed as a request then a MessageContract must also be returned as a response (or void).
These rules help enforce a request/response pattern. So if you implement this pattern in your service then this helps ensure that the people who maintain your service will be more likely to extend the request/response pattern because of the built-in validation
that WCF provides with MessageContracts.
What are your thoughts on this perspective?