Reputation: 1237
When we create WCF Service, we have SrviceContract (Interface), OperationCOntract(Methods) and DataContract(Class types).
I am wondering if we can have OperationContract without DataContract. If yes, any Example would be great help.
Appreciate your time.
Thanks
Upvotes: 0
Views: 1215
Reputation: 1028
I'm not sure why you would want this, but if you return and/or pass nothing but primitives and nullables (strings, dates, int?s, etc...) and Lists/arrays of same, you won't need to create any data contracts. Any structured data you want to pass requires a DataContract attribute or else an exception will be thrown.
So, some examples that would work are...
[ServiceContract]
public interface ISimpleContract
{
[OperationContract] void DoSomething();
[OperationContract] int GetNumber();
[OperationContract] string GetStatus(int userId);
[OperationContract] string[] GetCodes(int? byDepartment);
[OperationContract] List<int> GetNumberOfStrings(string[] strings);
}
Upvotes: 3
Reputation: 40413
The DataContract
attribute just represents a class that will be used in signatures in your service. So if your service doesn't need to refer to any of your classes, you won't have a DataContract
attribute anywhere.
For example, if you have just methods that accept and return primitive types like strings or numbers, then you wouldn't have to define any of your own classes.
Upvotes: 3