我希望能够从非结构应用程序或服务调用有状态的 HTTP/WebApi 服务。我可以将发布的 url 用于有状态服务,但希望通过解析分区端点来利用故障转移到不同的主节点。
我首先尝试在桌面控制台应用程序中进行测试,但它无法执行 InvokeWithRetryAsync 内部的通信 Lambda 函数。
这是死胡同(非结构应用程序无法解析有状态服务)还是有另一种方法可以从非结构应用程序解析端点。否则,我可能会将请求包装在“中间人”无状态服务(如 Wordcount Webservice)中。
var result = await servicePartitionClient.InvokeWithRetryAsync(
client =>
{
//never reaches here.
Uri serviceAddress = new Uri(client.BaseAddress, "SetConfiguration");
HttpWebRequest request = WebRequest.CreateHttp(serviceAddress);
request.Method = "POST";
//Add the content into the body
byte[] byteArray = Encoding.UTF8.GetBytes(_datapacket);
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
request.Timeout = (int)client.OperationTimeout.TotalMilliseconds;
request.ReadWriteTimeout = (int)client.ReadWriteTimeout.TotalMilliseconds;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//for now, just return ok
return Task.FromResult<string>("ok");
});