Под атрибутом ServiceContract лучше всего определять интерфейс. Можно, конечно, и класс, но лучше через интерфейс действовать.
А потом просто от него наследоваться, и не нужно в классе будет атрибут опеределять.
Так легче разрабатывать и сопровождать.
Обязательно методы, которые вы хотите предлагать для использования, должны быть под атрибутом OperationContract
The ServiceContractAttribute is defined as:
[AttributeUsage(AttributeTargets.Interface|AttributeTargets.Class, Inherited = false)]
public sealed class ServiceContractAttribute : Attribute
{
public string Name {get;set;}
public string Namespace {get;set;}
public sealed class ServiceContractAttribute : Attribute
{
public string Name {get;set;}
public string Namespace {get;set;}
//More members
}
}
ПРИМЕР
// Service contract describing the operations provided by the WCF service
[ServiceContract]
public interface IProductsService
{
// Get the product number of every product
[OperationContract]
List<string> ListProducts();
// Get the details of a single product
[OperationContract]
ProductData GetProduct(string productNumber);
// Get the current stock level for a product
[OperationContract]
int CurrentStockLevel(string productNumber);
// Change the stock level for a product
[OperationContract]
bool ChangeStockLevel(string productNumber, short newStockLevel, string shelf,
int bin);
}
// Service contract describing the operations provided by the WCF service
[ServiceContract]
public interface IProductsService
{
// Get the product number of every product
[OperationContract]
List<string> ListProducts();
// Get the details of a single product
[OperationContract]
ProductData GetProduct(string productNumber);
// Get the current stock level for a product
[OperationContract]
int CurrentStockLevel(string productNumber);
// Change the stock level for a product
[OperationContract]
bool ChangeStockLevel(string productNumber, short newStockLevel, string shelf,
int bin);
}
Комментариев нет:
Отправить комментарий