I have .NET C⯠application with WCF. I have implemented simple hello World and read simple operation from database but I am getting wcf Async method automatically along with my method.
I have two question
1- How can remove if I don't want to implement from WCF services
2- If I want to, how I implement WCF Async Method
I have two method for HeloWorld but got additional methods
Standard Method
namespace App.Services.Contracts
{
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
string GetMessage(string name);
}
}
Async Method
namespace App.Services.Contracts
{
[ServiceContract]
public interface IHelloWorldServiceAsyn
{
[OperationContract]
Task<string> GetMessageAsyn(string name);
}
}
Implementation of HelloWorld Services
public class HelloWorldManager : IHelloWorldService, IHelloWorldServiceAsyn
{
public String GetMessage(string name)
{
return "This is test Service Flow, Hello world from " + name + "!";
}
public async Task<string> GetMessageAsyn(string name)
{
var task = Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);
return "This is test Service Flow, Hello world from " + name + "!";
});
return await task.ConfigureAwait(false);
}
}
Service Model Config
<service name="App.Services.Managers.HelloWorldManager" behaviorConfiguration="DefaultServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8087/CreditUnionServices/HelloWorldServices" />
</baseAddresses>
</host>
<endpoint address="HelloWorld" binding="wsHttpBinding" bindingConfiguration="DefaultBindingConfiguration" contract="App.Services.Contracts.IHelloWorldService"></endpoint>
<endpoint address="HelloWorldAsyn" binding="wsHttpBinding" bindingConfiguration="DefaultBindingConfiguration" contract="App.Services.Contracts.IHelloWorldServiceAsyn"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="DefaultMexBindingConfiguration" contract="IMetadataExchange"></endpoint>
</service>
you can see below screen shot that I have duplication of Async method, how I make sure it do not generate automatically so that when I need, I do it myself