You can do this in V2 stack, I haven't tried the V1 stack but it might work there too. Add a parameter of CancellationToken type to the method signature:
void HelloWorldAsync(CancellationToken cancellationToken);
this token will then get passed to ServicePartitionClient.InvokeWithRetryAsync method via the proxy.
The generated proxy method will look like the following:
Task<string> IMyService.HelloWorldAsync(CancellationToken cancellationToken)
{
IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody = base.CreateRequestMessageBodyV2("MyNamespace.IMyService", "HelloWorldAsync", 1);
Task<IServiceRemotingResponseMessageBody> task = base.InvokeAsyncV2(
1, -1, "HelloWorldAsync", serviceRemotingRequestMessageBody,
cancellationToken);
return base.ContinueWithResultV2<ServiceInfoResponse>(task);
}
Without the CancellationToken parameter the proxy method looks like:
Task<string> IMyService.HelloWorldAsync()
{
IServiceRemotingRequestMessageBody serviceRemotingRequestMessageBody = base.CreateRequestMessageBodyV2("MyNamespace.IMyService", "HelloWorldAsync", 1);
Task<IServiceRemotingResponseMessageBody> task = base.InvokeAsyncV2(
1, -1, "HelloWorldAsync", serviceRemotingRequestMessageBody,
CancellationToken.None);
return base.ContinueWithResultV2<ServiceInfoResponse>(task);
}
If you want to inspect the generated proxy assembly use the following attribute in the EntryPoint assembly or the assembly that has the service interface defined:
[assembly: CodeBuilder(EnableDebugging = true)]