-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Tsuyoshi Ushio edited this page Aug 12, 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);
:
This document is now up to Chapter 2. However, I've done up to Chapter 4 already. Enjoy via code until adding more info. Release notes for versioned sample
- Chapter 5 Code package
The code of the book works fine. However, we have a pitfall.
The batch file(cmd)'s default character encoding is different from Visual Studio. If you create cmd file via Visual Studio, it might be UTF-8 with BOM. In Japan, cmd's character encoding default is Shift_JIS.
The cmd will execute in Shift_JIS. Please check your default encoding of batch files of your country.
- Chapter 5 Data package
P99 Data package 4.
while (!cancellationToken.IsCancellationRequested)
{
var dataPackage = this.Context.CodePackageActivationContext.GetDataPackageObject("TestData");
var text = File.ReadAllText(Path.Combine(dataPackage.Path, "data.txt"));
ServiceEventSource.Current.ServiceMessage(this, text);
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
}