Click here to Skip to main content
15,894,896 members
Articles / .NET / .NET4

A Simple Sample: WCF Service

Rate me:
Please Sign up or sign in to vote.
4.65/5 (30 votes)
1 Nov 201011 min read 481.1K   51.3K   84  
Writing, configuring, and consuming a WCF Service using VS2010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfServiceLibrary1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Team Leader
Pakistan Pakistan
Interesting technologies:
.NET, RIA, EIA, SOAP, XML, LINQ, WCF, WPF, Silverlight, ASP.NET MVC, jQuery, CSS, HTML5.

Interesting products:
MOSS 2010, Microsoft Dynamics CRM 2010

http://izlooite.blogspot.com

Comments and Discussions