Создание Службы Restful WCF
EvalService.в CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.ServiceModel; namespace CreateWcfServiceLibrary { [DataContract] public class Eval { [DataMember] public string Submitter; [DataMember] public DateTime TimeSent; [DataMember] public string Comments; } [ServiceContract] public interface IEvalService { [OperationContract(IsOneWay=true)] void SubmitEval(Eval eval); [OperationContract] List<eval> GetList(); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] class EvalService: IEvalService { List<eval> evals = new List<eval>(); #region IEvalService Members public void SubmitEval(Eval eval) { evals.Add(eval); } public List<eval> GetList() { return evals; } #endregion } }
Клиент
Программы.в CS
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ClientConsole.EvalServiceReference; namespace ClientConsole { class Program { static void Main(string[] args) { EvalServiceClient client = new EvalServiceClient("WSHttpBinding_IEvalService"); Eval evalItems = new Eval(); evalItems.Comments = "This comment from Code."; evalItems.Submitter = "vaibhav"; evalItems.TimeSent = DateTime.Now; client.SubmitEval(evalItems); Eval[] evals = client.GetList(); foreach (Eval ev in evals) { Console.WriteLine(ev.Comments); Console.WriteLine(ev.Submitter); Console.WriteLine(ev.TimeSent); Console.ReadKey(); } } } }
Принимающий
ивал.ВПВ
<%@ ServiceHost Service="CreateWcfServiceLibrary.EvalService" %> Web.config <pre lang="xml"><system.serviceModel> <services> <service behaviorConfiguration="WcfServiceHost.Service1Behavior" name="CreateWcfServiceLibrary.EvalService"> <endpoint address="ws" binding="wsHttpBinding" contract="CreateWcfServiceLibrary.IEvalService"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WcfServiceHost.Service1Behavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel></pre>
Espen Harlinn
А у вас неприятности именно какие?