with a class attributed to service model and the made to single instance
in the attribute itself.
[ServiceBehavior(InstanceContextMode =InstanceContextMode.Single)]
so this class implements all the methods this service ahould do and also called as service behaviour
here is the class
[ServiceBehavior(InstanceContextMode =InstanceContextMode.Single)]
public class EvalService : iEvalContract
{
List m_Evals = new List();
#region iEvalContract Members
public void SubmitEval(Eval i_eval)
{
i_eval.id = Guid.NewGuid().ToString();
m_Evals.Add(i_eval);
}
public List GetEvals()
{
return m_Evals;
}
public void RemoveEval(string id)
{
m_Evals.Remove(m_Evals.Find(e => e.id.Equals(id)));
}
#endregion
}
this class implemets a interface which can be called as service contract
here is the class
[ServiceContract]
public interface iEvalContract
{
[OperationContract]
void SubmitEval(Eval i_eval);
[OperationContract]
List GetEvals();
[OperationContract]
void RemoveEval(string id);
}
here the each method is decalred with a attribute operational contract
for this a model data contract is defined with the datamembers attributes which exposes the members to the service user
[DataContract]
public class Eval
{
[DataMember]
public string id;
[DataMember]
public string name;
[DataMember]
public DateTime modifiedDate;
}
WCF vs WEB service
WEB service
XML serializer
which needs the class to implement ienumerable
can't serialize idictionary members
only publics are translated to XML
further read this