Services in projects are quite common these days, as they help the other components/systems to interact with your system and exchange information. Your service may contain many methods which reflects your system functionality, like GetProductsByCategoryId, UpdateSalesOrderByOrderId etc.
However, it may not be a good idea to share these names with other systems, especially if they are any external systems. In such a case, we can easily avoid this situation when we are using WCF services. Let's see how we can do this.
To start with, we will create a new WCF service and access its method in a sample web application. So our service code will look like the following:
- [ServiceContract]
- public interface IService1
- {
- [OperationContract]
- string GetData(int value);
- }
- public class Service1 : IService1
- {
- public string GetData(int value)
- {
- return string.Format("You entered: {0}", value);
- }
- }
Next, we add its reference in a webproject and access the method GetData. So the code will look like the following:
- ServiceReference1.Service1Client _client = new ServiceReference1.Service1Client();
- var _data = _client.GetData(2);
Now, we do not want to share the name of this method as it is. So we would like to call it something like GetMyData. For this we will add the Name property on the OperationContract attribute and specify it's value as GetMyData. So the code will look like the following:
- [ServiceContract]
- public interface IService1
- {
- [OperationContract(Name="GetMyData")]
- string GetData(int value);
- }
Run the application and we can see the results. Similarly, we can add the Name property on the ServiceContract, DataContract and DataMember attributes.
Happy coding...!!!
Read more articles on WCF:

Rahul Kumar SaxenaPosted Apr 30, 2016, 1:58 PM
Good Work
AniPosted Apr 27, 2016, 3:09 AM
thanks for sharing
Sonu ChaudharyPosted Apr 26, 2016, 4:05 AM
thnaks for article
Akash MalhotraPosted Apr 26, 2016, 3:31 AM
Nice article
Gowtham RajamanickamPosted Apr 26, 2016, 2:55 AM
good article
Kuppurasu NagarajPosted Apr 25, 2016, 11:59 AM
Nice Sharing
Jaipal ReddyPosted Apr 25, 2016, 9:02 AM
Nice
Vignesh ManiPosted Apr 25, 2016, 8:15 AM
Nice