Click here to Skip to main content
15,881,860 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
EvalService.cs
C#
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
    }
}

Client
Program.cs
C#
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();
            }
        }
    }
}

Hosting
eval.svc
XML
<%@ ServiceHost Service="CreateWcfServiceLibrary.EvalService"  %>
Web.config
<pre lang="xml">&lt;system.serviceModel&gt;
    &lt;services&gt;
        &lt;service behaviorConfiguration=&quot;WcfServiceHost.Service1Behavior&quot; name=&quot;CreateWcfServiceLibrary.EvalService&quot;&gt;
            &lt;endpoint address=&quot;ws&quot; binding=&quot;wsHttpBinding&quot; contract=&quot;CreateWcfServiceLibrary.IEvalService&quot;&gt;
                &lt;identity&gt;
                    &lt;dns value=&quot;localhost&quot;/&gt;
                &lt;/identity&gt;
            &lt;/endpoint&gt;
            &lt;endpoint address=&quot;mex&quot; binding=&quot;mexHttpBinding&quot; contract=&quot;IMetadataExchange&quot;/&gt;
        &lt;/service&gt;
    &lt;/services&gt;
    &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
            &lt;behavior name=&quot;WcfServiceHost.Service1Behavior&quot;&gt;
                &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
                &lt;serviceMetadata httpGetEnabled=&quot;true&quot;/&gt;
                &lt;!-- 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 --&gt;
                &lt;serviceDebug includeExceptionDetailInFaults=&quot;false&quot;/&gt;
            &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;
&lt;/system.serviceModel&gt;</pre>
Posted
Updated 18-Mar-18 14:19pm
v2
Comments
Espen Harlinn 14-Jun-12 14:23pm    
And you trouble is exactly what?

1 solution

Start by having a look at: A Developer's Guide to the WCF REST Starter Kit[^]

You'll find additional useful information here:WCF Web HTTP Programming Model[^]

One thing I immediately noticed is that in addition to OperationContact you need to decorate the methods with WebGet[^] or WebInvoke[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sandeep Mewara 14-Jun-12 16:30pm    
My 5 ! Good answer.
Espen Harlinn 14-Jun-12 16:30pm    
Thank you Sandeep :-D
VJ Reddy 14-Jun-12 20:13pm    
Nice answer with good references. 5!
Espen Harlinn 14-Jun-12 20:29pm    
Thank you, VJ :-D
Abhinav S 15-Jun-12 2:38am    
5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900