Skip to content

Instantly share code, notes, and snippets.

@scott-kloud
Last active April 17, 2017 08:38
Show Gist options
  • Save scott-kloud/305576eb216cbb69b8363d57a3b7b780 to your computer and use it in GitHub Desktop.
Save scott-kloud/305576eb216cbb69b8363d57a3b7b780 to your computer and use it in GitHub Desktop.
#r "System.ServiceModel"
#r "Blog.Apr2017.TimeMachineServiceClient.dll"
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Blog.Apr2017.TimeMachineServiceClient.TimeMachineService;
public static void Run(SpaceTimeCoords request, TraceWriter log)
{
// Create endpoint address gathered from functions app settings
var address = new EndpointAddress(System.Environment.GetEnvironmentVariable("TimeMachineServiceEndpoint", EnvironmentVariableTarget.Process));
// Create binding to match the client proxy configuration
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
// Create an instance of our client proxy passing in binding and endpoint address
var client = new ControlServiceClient(binding, address);
// Add client credentials from functions app settings
client.ClientCredentials.UserName.UserName = System.Environment.GetEnvironmentVariable("TimeMachineServiceUserName", EnvironmentVariableTarget.Process);
client.ClientCredentials.UserName.Password = System.Environment.GetEnvironmentVariable("TimeMachineServicePassword", EnvironmentVariableTarget.Process);
// Invoke service operation
var response = client.SetTimeCoords(request);
// Output response
log.Info($"Response from time machine. Code: {response.Code} Message: {response.Message}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment