using Grpc.Net.Client;
|
using Grpc.Net.Client.Web;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net.Http;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace HotelPms.Data.Client
|
{
|
public class GrpcFactory : IDisposable
|
{
|
public static string Url = "https://localhost:7240"; //托管
|
//public static string Url = "https://localhost:5001"; //
|
//public static string Url = "https://133.125.63.43:46492"; //Web ⇒OK
|
|
private static GrpcFactory m_Default = null;
|
|
public static GrpcFactory Instance
|
{
|
get
|
{
|
if (m_Default == null) { m_Default = new GrpcFactory(); }
|
return m_Default;
|
}
|
}
|
|
|
|
/// <summary>
|
/// チャネル
|
/// </summary>
|
public GrpcChannel Channel { get; private set; } = null;
|
|
/// <summary>
|
/// GrpcTableの取得、更新用クライアント
|
/// </summary>
|
public GrpcTableCore.GrpcTableCoreClient TableCore { get; private set; } = null;
|
|
/// <summary>
|
/// GrpcSetの取得、更新用クライアント
|
/// </summary>
|
public GrpcSetCore.GrpcSetCoreClient SetCore { get; private set; } = null;
|
|
#region 各テーブルのクラウド
|
|
//public MenuCore.MenuCoreClient Menu { get; private set; } = null;
|
|
#endregion
|
|
public GrpcFactory()
|
{
|
var httpClientHandler = new HttpClientHandler();
|
httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
|
var httpClient = new HttpClient(new GrpcWebHandler(GrpcWebMode.GrpcWeb, httpClientHandler));
|
//var httpClient = new HttpClient(httpClientHandler);
|
GrpcChannelOptions options = new GrpcChannelOptions()
|
{
|
MaxReceiveMessageSize = int.MaxValue,
|
HttpClient = httpClient
|
};
|
Channel = GrpcChannel.ForAddress(Url, options);
|
TableCore = new GrpcTableCore.GrpcTableCoreClient(Channel);
|
SetCore = new GrpcSetCore.GrpcSetCoreClient(Channel);
|
|
#region 各テーブルのクラウド
|
|
//Menu = new MenuCore.MenuCoreClient(Channel);
|
|
#endregion
|
}
|
|
public void Dispose()
|
{
|
if (Channel != null) { Channel.Dispose(); }
|
}
|
}
|
}
|