Home › Services / Web Services / Internet › WCF Specify Names of Contracts
Services / Web Services / Internet · Nov 3, 2015 · 1 MIN READ

WCF Specify Names of Contracts

Consider a WCF service that returns some text that you entered. The service has a contract called IService1 and an operation called GetData. When we run the service in our test client, we see:

The code for this is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace Carl.TestWCF
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

    }
}

Let’s say we want the service and operation to be different to what the WCF consumer will see. In order to do this, we decorate our methods below with:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace Carl.TestWCF
{
    [ServiceContract(Name = "Return What Was Entered")]
    public interface IService1
    {
        [OperationContract(Name ="Do The Returning")]
        string GetData(int value);

    }
}

When we run our test client now, we can see the names have changed:

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.