-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Tsuyoshi Ushio edited this page Aug 9, 2016
·
7 revisions
- Chapter 2 The First Version
CalculatorService.cs
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(context =>
this.CreateServiceRemotingListener(context))
};
}
Program.cs
ServiceRuntime.RegisterServiceAsync("CalculatorServiceType",
context => new CalculatorService(context)).GetAwaiter().GetResult();
- Chapter 2 The Second version
public Task<string> Add(int a, int b)
{
return Task.FromResult<string>(string.Format("Instance {0} returns: {1}",
this.Context.InstanceId,
a + b));
}
public Task<string> Subtract(int a, int b)
{
return Task.FromResult<string>(string.Format("Instance {0} returns: {1}",
this.Context.InstanceId,
a - b));
}
- Chapter 2 The third version
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(context =>
new WcfCommunicationListener<ICalculatorService>(
wcfServiceObject:this,
serviceContext:context,
endpointResourceName: "ServiceEndpoint",
listenerBinding: WcfUtility.CreateTcpListenerBinding()
)
)};
}
This revision is enable us to route http://localhost:80/webapp/api/...
as the book says.
public OwinCommunicationListener(IOwinAppBuilder startup, ServiceContext serviceContext, string appRoot)
{
this.startup = startup;
this.serviceContext = serviceContext;
this.appRoot = appRoot;
}
public Task<string> OpenAsync(CancellationToken cancellationToken)
{
EndpointResourceDescription serviceEndpoint = this.serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint");
int port = serviceEndpoint.Port;
this.listeningAddress = String.Format("http://+:{0}/{1}/", port, appRoot);
: