Mandatory Parameters in Request object (WCF)
lHi,
I'm currently writing a WCF service. One of those methods get's a request object and returns a response object. In the request there are a couple of value-type members.
Is there a way to define members are mandatory in the declarative way? I'm in an early stage of development and I don't want to start with versioning now. In addition I don't want to have method sig with 25 parameters, therefore I created the request object.
The problem I have is that due to the value-types, I can never be sure if the consumer of the service intended to have the default value in there, or it was just by lazyness. On consumer side you don't easily detect that you probably missed that property.
So I would like to have something that forces the caller of the service to 开发者_JS百科provide an value, and if not he ideally get's a compile-time error.
any ideas?
tia, Martin
Yes, absolutely:
[DataContract]
public class YourRequestClass
{
[DataMember(IsRequired=true)]
int RequestID { get; set; }
}
There are a number of sub-attributes to the DataMember
attribute that you can use - Order
and IsRequired
probably being the most frequently used ones.
Please check if the following is resolving your issue:
IsRequired/EmitDefaultValue Attribute on DataMember
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/d9e45449-cc50-42e2-b955-75ab86f01d4f
The topic above describes a combination of
IsRequired
and EmitDefaultValue
attributes set on a request member, which according to the discussion there at least seams to resolve the "issue"
cheers
精彩评论