Robert 2 жил өмнө
parent
commit
e3587c8549

+ 103 - 88
EVCB_OCPP.WEBAPI/Controllers/Version1/CPOController.cs

@@ -33,7 +33,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         private HttpClientService service = new HttpClientService();
         private readonly IServiceProvider serviceProvider;
 
-        public CPOController(IServiceProvider serviceProvider)
+        public CPOController(IServiceProvider serviceProvider, IConfiguration configuration)
         {
             this.serviceProvider = serviceProvider;
         }
@@ -72,7 +72,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     statusCode = StatusCodes.Status200OK;
                 }
                 //return Request.CreateResponse(statusCode, result);
-                return StatusCode(statusCode,result);
+                return StatusCode(statusCode, result);
             }
             catch (Exception ex)
             {
@@ -151,12 +151,8 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 //return Request.CreateResponse(statusCode, result);
                 return StatusCode(statusCode, result);
             }
-
-
         }
 
-
-
         [Route("commands/start_session")]
         [Produces(typeof(CPOOuterResponse))]
         [HttpPost]
@@ -190,31 +186,28 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                    || (_CPService.GetNumberofConnectors(request.ChargeBoxId) >= request.ConnectorId && request.ConnectorId > 0))
                     && !string.IsNullOrEmpty(request.Token) && request.Token.Length <= 20)
                 {
-
-                    InternalHttpClient _client = new InternalHttpClient();
+                    InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                     ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                     //trigger to charge
                     var _request = new Models.WebAPI.StartTransactionRequest()
                     {
                         ConnectorId = request.ConnectorId,
-                        IdTag = request.Token                     
-                       
+                        IdTag = request.Token
+
                     };
 
-                    string url = Request.GetDisplayUrl();
-                    string[] parts = url.Split('/');
-                    string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={3}";
+                    string[] parts = Request.GetDisplayUrl().Split('/');
+                    string urlformat = "{0}//{1}";
 
                     var _innerResult = await _client.Post(
-                        string.Format(urlformat, parts[0], parts[2], new Uri(url).Port.ToString(), request.ChargeBoxId)
-                        ,new Dictionary<string, string>()
+                        string.Format(urlformat, parts[0], parts[2])
+                        , $"/api/v1/ocpp16/transaction?ChargeBoxId={request.ChargeBoxId}"
+                        , new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
-
                         }, _request, _customer.GetAPIKey(new Guid(_CustomerId)));
 
-
                     _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
                     result = GetErrorDescription(_innerResult);
                     result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
@@ -292,18 +285,23 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={2}&TransactionId={3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Put(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, SessionId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Put(
+                    string.Format(urlformat, parts[0], parts[2] ), 
+                    $"/api/v1/ocpp16/transaction?ChargeBoxId={ChargeBoxId}&TransactionId={SessionId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, null, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, 
+                    null, 
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -378,11 +376,11 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
-                string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}";
+                string urlformat = "{0}//{1}";
 
                 var _innerRequest = new ReserveRequest()
                 {
@@ -392,11 +390,16 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     ExpiryDate = request.ExpiryDate.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT)
                 };
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], request.ChargeBoxId), new Dictionary<string, string>()
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    $"/api/v1/ocpp16/reservation?ChargeBoxId={request.ChargeBoxId}",
+                    new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
-                        }, _innerRequest, _customer.GetAPIKey(new Guid(_CustomerId)));
+                        },
+                    _innerRequest,
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -469,19 +472,21 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
-
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}&ReservationId={3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ReservationId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Delete(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp16/reservation?ChargeBoxId={ChargeBoxId}&ReservationId={ReservationId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -503,7 +508,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                         result.StatusMessage = CPO_StatusMessage.ERROR_MSG_INNERSERVICE_ERROR;
                         //statusCode = HttpStatusCode.BadRequest;
                         statusCode = StatusCodes.Status400BadRequest;
-                    }                        
+                    }
                     else
                     {
                         result.StatusCode = _innerResult.ErrorCode;
@@ -553,19 +558,21 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
-
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/compositeschedule?ChargeBoxId={2}&ConnectorId={3}&Duration={4}&ChargingRateUnit={5}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ConnectorId, Duration, ChargingRateUnit), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    $"/api/v1/ocpp16/compositeschedule?ChargeBoxId={ChargeBoxId}&ConnectorId={ConnectorId}&Duration={Duration}&ChargingRateUnit={ChargingRateUnit}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -638,20 +645,23 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}";
-
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
-
-                        }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
+                string urlformat = "{0}//{1}";
 
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp16/chargingprofile?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId", _CustomerId}
+                    }, 
+                    request,
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
                 result = GetErrorDescription(_innerResult);
@@ -737,19 +747,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}{3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Delete(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    string.Format("/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}{3}", ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId),
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -821,24 +834,24 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/locallist?ChargeBoxId={2}";
-
-
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp16/locallist?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
                         }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
 
-
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
                 result = GetErrorDescription(_innerResult);
                 result.Data = JsonConvert.SerializeObject(_innerData, EVCBConfiguration.JSONSERIALIZER_FORMAT);
@@ -911,18 +924,19 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
 
                 string[] parts = Request.GetDisplayUrl().ToString().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/locallistversion?ChargeBoxId={2}";
-
-
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2] ), 
+                    $"/api/v1/ocpp16/locallistversion?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
@@ -1001,7 +1015,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 int? orderNo = (int?)null;
@@ -1064,15 +1078,16 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
+                string urlformat = "{0}//{1}";
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/command?ChargeBoxId={2}{3}&SerialNo={4}";
-
-
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    string.Format("/api/v1/ocpp16/command?ChargeBoxId={0}{1}&SerialNo={2}", ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo),
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 result = GetErrorDescription(_innerResult);
@@ -1253,7 +1268,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                     {
 
 
-                        string currencyText = string.IsNullOrEmpty(transactionData.Fee) ? "TWD" : transactionData.Fee.Remove(0, transactionData.Fee.Length - 3); 
+                        string currencyText = string.IsNullOrEmpty(transactionData.Fee) ? "TWD" : transactionData.Fee.Remove(0, transactionData.Fee.Length - 3);
 
                         _innerData.Add(new ActiveSession()
                         {
@@ -1378,7 +1393,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 1;
@@ -1440,7 +1455,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 2;
@@ -1493,7 +1508,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("statistics/time_of_use")]
         [Produces(typeof(CPOOuterResponse))]
         [HttpPost]
-        async public Task<IActionResult> Time_of_Use([FromBody] StatisticsRequest request, [FromServices]IConfiguration configuration)
+        async public Task<IActionResult> Time_of_Use([FromBody] StatisticsRequest request, [FromServices] IConfiguration configuration)
         {
             var result = new CPOOuterResponse();
             //HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
@@ -1502,7 +1517,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 3;
@@ -1555,7 +1570,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("statistics/peak_load")]
         [Produces(typeof(CPOOuterResponse))]
         [HttpPost]
-        async public Task<IActionResult> Peak_Load([FromBody] StatisticsRequest request, [FromServices]IConfiguration configuration)
+        async public Task<IActionResult> Peak_Load([FromBody] StatisticsRequest request, [FromServices] IConfiguration configuration)
         {
             var result = new CPOOuterResponse();
             //HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
@@ -1564,7 +1579,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 4;
@@ -1616,7 +1631,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("statistics/sessions")]
         [Produces(typeof(CPOOuterResponse))]
         [HttpPost]
-        async public Task<IActionResult> Sessions([FromBody] StatisticsRequest request, [FromServices]IConfiguration configuration)
+        async public Task<IActionResult> Sessions([FromBody] StatisticsRequest request, [FromServices] IConfiguration configuration)
         {
             var result = new CPOOuterResponse();
             //HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
@@ -1625,7 +1640,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 6;
@@ -1669,7 +1684,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
                 result.StatusMessage = CPO_StatusMessage.ERROR_MSG_UNEXPECTEDERROR;
                 result.StatusCode = (int)CPO_StatusCode.UnexpectedError;
                 //return Request.CreateResponse(statusCode, result);
-                return StatusCode(statusCode,result);
+                return StatusCode(statusCode, result);
             }
 
             //return Request.CreateResponse(statusCode, result);
@@ -1679,7 +1694,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
         [Route("statistics/fault")]
         [Produces(typeof(CPOOuterResponse))]
         [HttpPost]
-        async public Task<IActionResult> Fault([FromBody] StatisticsRequest request, [FromServices]IConfiguration configuration)
+        async public Task<IActionResult> Fault([FromBody] StatisticsRequest request, [FromServices] IConfiguration configuration)
         {
             var result = new CPOOuterResponse();
             //HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
@@ -1688,7 +1703,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 5;
@@ -1736,7 +1751,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version1
 
             //return Request.CreateResponse(statusCode, result);
             return StatusCode(statusCode, result);
-        }  
+        }
 
         private string GetStatisticChargeBoxIds(List<string> chargeBoxIds)
         {

+ 72 - 45
EVCB_OCPP.WEBAPI/Controllers/Version2/V2_CPOController.cs

@@ -318,7 +318,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                 && !string.IsNullOrEmpty(request.Token) && request.Token.Length <= 20)
                 {
 
-                    InternalHttpClient _client = new InternalHttpClient();
+                    InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                     ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                     //trigger to charge
@@ -329,14 +329,19 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                     };
 
                     string[] parts = Request.GetDisplayUrl().ToString().Split('/');
-                    string urlformat = "{0}//{1}/api/v1/ocpp{2}/transaction?ChargeBoxId={3}";
+                    string urlformat = "{0}//{1}";
+                    string ocppProtocol = GetChargePointOCPPProtocol(request.ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
-                    var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2],
-                        GetChargePointOCPPProtocol(request.ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20", request.ChargeBoxId), new Dictionary<string, string>()
+                    var _innerResult = await _client.Post(
+                        string.Format(urlformat, parts[0], parts[2]),
+                        $"/api/v1/ocpp{ocppProtocol}/transaction?ChargeBoxId={request.ChargeBoxId}",
+                        new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
-                        }, _request, _customer.GetAPIKey(new Guid(_CustomerId)));
+                        },
+                        _request, 
+                        _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                     _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -410,18 +415,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                     return StatusCode(statusCode, result);
                 }
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp{2}/transaction?ChargeBoxId={3}&TransactionId={4}";
+                string urlformat = "{0}//{1}";
+                string ocppProtocol = GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
-                var _innerResult = await _client.Put(string.Format(urlformat, parts[0], parts[2], GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20", ChargeBoxId, SessionId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Put(
+                    string.Format(urlformat, parts[0], parts[2], ocppProtocol, ChargeBoxId, SessionId), 
+                    $"/api/v1/ocpp{ocppProtocol}/transaction?ChargeBoxId={ChargeBoxId}&TransactionId={SessionId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, null, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, null, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -491,11 +500,12 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
-                string urlformat = "{0}//{1}/api/v1/ocpp{2}/reservation?ChargeBoxId={3}";
+                string urlformat = "{0}//{1}";
+                string ocppProtocol = GetChargePointOCPPProtocol(request.ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
                 var _innerRequest = new ReserveRequest()
                 {
@@ -505,12 +515,16 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                     ExpiryDate = request.ExpiryDate.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT)
                 };
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2],
-                    GetChargePointOCPPProtocol(request.ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20", request.ChargeBoxId), new Dictionary<string, string>()
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2] ),
+                    $"/api/v1/ocpp{ocppProtocol}/reservation?ChargeBoxId={request.ChargeBoxId}",
+                    new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
-                        }, _innerRequest, _customer.GetAPIKey(new Guid(_CustomerId)));
+                        }, 
+                    _innerRequest,
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -579,20 +593,23 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().ToString().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp{2}/reservation?ChargeBoxId={3}&ReservationId={4}";
+                string urlformat = "{0}//{1}";
+                string ocppProtocol = GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
-                var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2],
-                    GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20", ChargeBoxId, ReservationId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Delete(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp{ocppProtocol}/reservation?ChargeBoxId={ChargeBoxId}&ReservationId={ReservationId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -661,22 +678,26 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
+                string urlformat = "{0}//{1}";
+                string ocppProtocol = GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
-                string urlformat = "{0}//{1}/api/v1/ocpp{2}/locallist?ChargeBoxId={3}";
 
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp{ocppProtocol}/locallist?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2],
-                    GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20", ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
-
-                        }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, 
+                    request, 
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -745,21 +766,24 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp{2}/locallistversion?ChargeBoxId={3}";
+                string urlformat = "{0}//{1}";
+                string ocppProtocol = GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20",
-                    ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp{ocppProtocol}/locallistversion?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -829,7 +853,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
                     return StatusCode(statusCode, result);
                 }
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 int? orderNo = (int?)null;
@@ -890,15 +914,18 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp{2}/command?ChargeBoxId={3}{4}&SerialNo={5}";
+                string urlformat = "{0}//{1}";
+                var ocppPortocol = GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20";
 
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], GetChargePointOCPPProtocol(ChargeBoxId) == OCPPProtocolType.OCPP16 ? "16" : "20",
-                    ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    string.Format("/api/v1/ocpp{{0}}/command?ChargeBoxId={{1}}{{2}}&SerialNo={{3}}", ocppPortocol, ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo),
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 result = GetErrorDescription(_innerResult);

+ 97 - 66
EVCB_OCPP.WEBAPI/Controllers/Version2/ocpp16/OCPP16_CPOController.cs

@@ -192,7 +192,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                     && !string.IsNullOrEmpty(request.Token) && request.Token.Length <= 20)
                 {
 
-                    InternalHttpClient _client = new InternalHttpClient();
+                    InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                     ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                     //trigger to charge
@@ -203,10 +203,13 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                     };
 
                     string[] parts = Request.GetDisplayUrl().Split('/');
-                    string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={3}";
+                    string urlformat = "{0}//{1}";
 
                     var url = new Uri(Request.GetDisplayUrl());
-                    var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], url.Port, request.ChargeBoxId), new Dictionary<string, string>()
+                    var _innerResult = await _client.Post(
+                        string.Format(urlformat, parts[0], parts[2]), 
+                        $"/api/v1/ocpp16/transaction?ChargeBoxId={request.ChargeBoxId}",
+                        new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
@@ -288,18 +291,21 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/transaction?ChargeBoxId={2}&TransactionId={3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Put(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, SessionId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Put(
+                    string.Format(urlformat, parts[0], parts[2] ),
+                    $"/api/v1/ocpp16/transaction?ChargeBoxId={ChargeBoxId}&TransactionId={SessionId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, null, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, null, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -361,11 +367,11 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
-                string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}";
+                string urlformat = "{0}//{1}";
 
                 var _innerRequest = new ReserveRequest()
                 {
@@ -375,11 +381,16 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                     ExpiryDate = request.ExpiryDate.ToString(EVCBConfiguration.UTC_DATETIMEFORMAT)
                 };
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], request.ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp16/reservation?ChargeBoxId={request.ChargeBoxId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _innerRequest, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, 
+                    _innerRequest, 
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -439,19 +450,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/reservation?ChargeBoxId={2}&ReservationId={3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ReservationId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Delete(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp16/reservation?ChargeBoxId={ChargeBoxId}&ReservationId={ReservationId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -510,19 +524,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/compositeschedule?ChargeBoxId={2}&ConnectorId={3}&Duration={4}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ConnectorId, Duration), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    $"/api/v1/ocpp16/compositeschedule?ChargeBoxId={ChargeBoxId}&ConnectorId={ConnectorId}&Duration={Duration}", 
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -582,19 +599,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
 
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2] ), 
+                    $"/api/v1/ocpp16/chargingprofile?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -661,19 +681,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/chargingprofile?ChargeBoxId={2}{3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Delete(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    string.Format("/api/v1/ocpp16/chargingprofile?ChargeBoxId={0}{1}", ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId),
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -732,22 +755,24 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
+                string urlformat = "{0}//{1}";
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/locallist?ChargeBoxId={2}";
-
-
-
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2] ), 
+                    $"/api/v1/ocpp16/locallist?ChargeBoxId={ChargeBoxId}", 
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, request, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, 
+                    request, 
+                    _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -807,22 +832,25 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/locallistversion?ChargeBoxId={2}";
+                string urlformat = "{0}//{1}";
 
 
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2] ), 
+                    $"/api/v1/ocpp16/locallistversion?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -884,7 +912,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 int? orderNo = (int?)null;
@@ -948,14 +976,17 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp16/command?ChargeBoxId={2}{3}&SerialNo={4}";
+                string urlformat = "{0}//{1}";
 
 
-                var _innerResult = await _client.Get(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Get(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    string.Format("/api/v1/ocpp16/command?ChargeBoxId={0}{1}&SerialNo={2}", ChargeBoxId, orderNo.HasValue ? "&OrderNo=" + orderNo.Value : "", SerialNo),
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId))); ;
 
 
                 result = GetErrorDescription(_innerResult);
@@ -1242,7 +1273,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 1;
@@ -1302,7 +1333,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 2;
@@ -1362,7 +1393,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 3;
@@ -1422,7 +1453,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 4;
@@ -1481,7 +1512,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 6;
@@ -1542,7 +1573,7 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp16
             try
             {
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
                 string url = configuration["StatisticsAPI"] + 5;

+ 21 - 12
EVCB_OCPP.WEBAPI/Controllers/Version2/ocpp201/OCPP201_CPOController.cs

@@ -79,15 +79,18 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp201
 
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp20/chargingprofile?ChargeBoxId={2}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId), new Dictionary<string, string>()
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]), 
+                    $"/api/v1/ocpp20/chargingprofile?ChargeBoxId={ChargeBoxId}",
+                    new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 
@@ -160,19 +163,22 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp201
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp20/chargingprofile?ChargeBoxId={2}{3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Delete(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId), new Dictionary<string, string>()
-                        {
-                            { "PartnerId",_CustomerId}
+                var _innerResult = await _client.Delete(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    string.Format("/api/v1/ocpp20/chargingprofile?ChargeBoxId={0}{1}", ChargeBoxId, ChargeProfileId == -1 ? "" : "&Id=" + ChargeProfileId),
+                    new Dictionary<string, string>()
+                    {
+                        { "PartnerId",_CustomerId}
 
-                        }, _customer.GetAPIKey(new Guid(_CustomerId)));
+                    }, _customer.GetAPIKey(new Guid(_CustomerId)));
 
 
                 _innerData = new { Result = string.IsNullOrEmpty(_innerResult.SerialNo) ? CommandResponseType.Rejected.ToString() : CommandResponseType.Accepted.ToString(), Timeout = 60 };
@@ -231,15 +237,18 @@ namespace EVCB_OCPP.WEBAPI.Controllers.Version2.ocpp201
                 }
 
 
-                InternalHttpClient _client = new InternalHttpClient();
+                InternalHttpClient _client = serviceProvider.GetRequiredService<InternalHttpClient>();
                 ICustomerService _customer = serviceProvider.GetRequiredService<ICustomerService>();
 
 
                 string[] parts = Request.GetDisplayUrl().Split('/');
 
-                string urlformat = "{0}//{1}/api/v1/ocpp20/datatransfer?ChargeBoxId={2}{3}";
+                string urlformat = "{0}//{1}";
 
-                var _innerResult = await _client.Post(string.Format(urlformat, parts[0], parts[2], ChargeBoxId, "&MessageId=ID_CpConfiguration"), new Dictionary<string, string>()
+                var _innerResult = await _client.Post(
+                    string.Format(urlformat, parts[0], parts[2]),
+                    $"/api/v1/ocpp20/datatransfer?ChargeBoxId={ChargeBoxId}&MessageId=ID_CpConfiguration",
+                    new Dictionary<string, string>()
                         {
                             { "PartnerId",_CustomerId}
 

+ 2 - 0
EVCB_OCPP.WEBAPI/Dockerfile

@@ -4,6 +4,8 @@
 #For more information, please see https://aka.ms/containercompat
 
 FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
+RUN sed -i 's/TLSv1.2/TLSv1/g' /etc/ssl/openssl.cnf
+RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
 WORKDIR /app
 EXPOSE 80
 EXPOSE 443

+ 1 - 1
EVCB_OCPP.WEBAPI/EVCB_OCPP.WEBAPI.csproj

@@ -64,6 +64,6 @@
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <OutputPath>bin\</OutputPath>
     <UserSecretsId>ad233da0-f16a-42df-bcf6-a2f575f2d4e0</UserSecretsId>
-    <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
+    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
   </PropertyGroup>
 </Project>

+ 8 - 3
EVCB_OCPP.WEBAPI/Handlers/CPOAuthentication.cs

@@ -16,16 +16,19 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Http.Extensions;
 using System.IO;
 using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
 
 namespace EVCB_OCPP.WEBAPI.Handlers
 {
     public class CPOAuthentication : Attribute, IAuthorizationFilter
     {
         private readonly IServiceProvider serviceProvider;
+        private readonly ILogger logger;
 
-        public CPOAuthentication(IServiceProvider serviceProvider)
+        public CPOAuthentication(IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
         {
             this.serviceProvider = serviceProvider;
+            this.logger = loggerFactory.CreateLogger(nameof(CPOAuthentication));
         }
 
         public void OnAuthorization(AuthorizationFilterContext context)
@@ -77,6 +80,7 @@ namespace EVCB_OCPP.WEBAPI.Handlers
             catch (Exception ex)
             {
                 _errorResponse.StatusMessage = CPO_StatusMessage.ERROR_MSG_UNEXPECTEDERROR;
+                logger.LogError(ex, null, null);
             }
 
 
@@ -159,13 +163,14 @@ namespace EVCB_OCPP.WEBAPI.Handlers
 
             //Task<string> content = actionContext.Request.Body.Content.ReadAsStringAsync();
             //string body = content.Result;
-            string body = new StreamReader(actionContext.Request.Body).ReadToEndAsync().Result;//.ReadToEnd();
+            actionContext.Request.Body.Position = 0;
+            string body = new StreamReader(actionContext.Request.Body).ReadToEnd();
+            actionContext.Request.Body.Position = 0;
             string diplayUrl = actionContext.Request.GetDisplayUrl();
             string tempText = diplayUrl.Substring(diplayUrl.IndexOf('?') + 1).ToLower();
             tempText = tempText.StartsWith("http") ? string.Empty : tempText;
             body = tempText + body;
 
-
             string unencodeText = string.Format("{0}{1}{2}{3}", body, timestamp, partnerId, key).ToLower();
             string signVerification = GenerateSignature(unencodeText);
             if (signVerification == signature)

+ 1 - 0
EVCB_OCPP.WEBAPI/Handlers/InernalAuthentication.cs

@@ -168,6 +168,7 @@ namespace EVCB_OCPP.WEBAPI.Handlers
 
             //Task<string> content = actionContext.Request.Content.ReadAsStringAsync();
             //string body = content.Result;
+            actionContext.Request.Body.Position = 0;
             string body = new StreamReader(actionContext.Request.Body).ReadToEndAsync().Result;//.ReadToEnd();
             string diplayUrl = actionContext.Request.GetDisplayUrl();
             string tempText = diplayUrl.Substring(diplayUrl.IndexOf('?') + 1).ToLower();

+ 7 - 5
EVCB_OCPP.WEBAPI/Middleware/APILogMiddleware.cs

@@ -36,6 +36,7 @@ public class APILogMiddleware
 
         var apiLogEntry = CreateApiLogEntryWithRequestData(request);
 
+        context.Request.Body.Position = 0;
         await new StreamReader(context.Request.Body).ReadToEndAsync()
             .ContinueWith(task =>
             {
@@ -82,6 +83,7 @@ public class APILogMiddleware
             {
                 fakeResponseBody.Seek(0, SeekOrigin.Begin);
                 var bodyData = await new StreamReader(response.Body).ReadToEndAsync();
+                response.Body.Position = 0;
 
                 apiLogEntry.ResponseContentBody = bodyData;
                 apiLogEntry.ResponseContentType = response.Headers.ContentType;
@@ -148,7 +150,6 @@ public class APILogMiddleware
     {
         try
         {
-
             if (log == null) return;
             using (var conn = new SqlConnection(apiLogConnectionString))
             {
@@ -159,13 +160,14 @@ public class APILogMiddleware
 
                     cmd.CommandType = System.Data.CommandType.StoredProcedure;
                     cmd.Parameters.Add(new SqlParameter("Application", log.Application));
-                    cmd.Parameters.Add(new SqlParameter("User", log.User));
+                    cmd.Parameters.Add(new SqlParameter("User", (string.IsNullOrEmpty(log.User) ? "" : log.User)));
                     cmd.Parameters.Add(new SqlParameter("Machine", log.Machine));
                     cmd.Parameters.Add(new SqlParameter("RequestIpAddress", log.RequestIpAddress));
-                    cmd.Parameters.Add(new SqlParameter("RequestContentType", log.RequestContentType));
+                    cmd.Parameters.Add(new SqlParameter("RequestContentType", (string.IsNullOrEmpty(log.RequestContentType) ? "" : log.RequestContentType)));
                     cmd.Parameters.Add(new SqlParameter("RequestUri", log.RequestUri));
                     cmd.Parameters.Add(new SqlParameter("RequestMethod", log.RequestMethod));
-                    cmd.Parameters.Add(new SqlParameter("RequestRouteTemplate", log.RequestRouteTemplate));
+                    //cmd.Parameters.Add(new SqlParameter("RequestRouteTemplate", log.RequestRouteTemplate));
+                    cmd.Parameters.Add(new SqlParameter("RequestRouteTemplate", ""));
                     cmd.Parameters.Add(new SqlParameter("RequestRouteData", ""));//log.RequestRouteData
                     cmd.Parameters.Add(new SqlParameter("RequestHeaders", log.RequestHeaders));
                     cmd.Parameters.Add(new SqlParameter("RequestTimestamp", log.RequestTimestamp));
@@ -181,7 +183,7 @@ public class APILogMiddleware
                     cmd.Parameters.Add(new SqlParameter("RequestContentBody", log.RequestContentBody));
                     cmd.Parameters.Add(new SqlParameter("ResponseContentBody", log.ResponseContentBody));
 
-                    cmd.ExecuteNonQuery();
+                    var result = cmd.ExecuteNonQuery();
                 }
             }
 

+ 45 - 0
EVCB_OCPP.WEBAPI/Middleware/BodyRewindMiddleware.cs

@@ -0,0 +1,45 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+using System.Threading.Tasks;
+using System;
+using System.IO;
+using System.Reflection.PortableExecutable;
+using Microsoft.AspNetCore.Mvc;
+
+namespace EVCB_OCPP.WEBAPI.Middleware;
+
+public sealed class BodyRewindMiddleware
+{
+    private readonly RequestDelegate _next;
+
+    public BodyRewindMiddleware(RequestDelegate next)
+    {
+        _next = next;
+    }
+
+    public async Task Invoke(HttpContext context)
+    {
+        string body = new StreamReader(context.Request.Body).ReadToEndAsync().GetAwaiter().GetResult();
+        using (var injectedRequestStream = new MemoryStream())
+        {
+            var bytesToWrite = System.Text.Encoding.UTF8.GetBytes(body);
+            injectedRequestStream.Write(bytesToWrite, 0, bytesToWrite.Length);
+            injectedRequestStream.Seek(0, SeekOrigin.Begin);
+            context.Request.Body = injectedRequestStream;
+            await _next(context);
+        }
+    }
+}
+public static class BodyRewindExtensions
+{
+    public static IApplicationBuilder EnableRequestBodyRewind(this IApplicationBuilder app)
+    {
+        if (app == null)
+        {
+            throw new ArgumentNullException(nameof(app));
+        }
+
+        return app.UseMiddleware<BodyRewindMiddleware>();
+    }
+
+}

+ 1 - 1
EVCB_OCPP.WEBAPI/Properties/AssemblyInfo.cs

@@ -24,7 +24,7 @@ using System.Runtime.InteropServices;
 
 [assembly: AssemblyVersion("2.0.2.0")]
 [assembly: AssemblyFileVersion("2.0.2.0")]
-[assembly: AssemblyInformationalVersion("2.0.2-dockerlize.1+5.Branch.dockerlize.Sha.c2e74b89150adc5ca6750a09896d93ca2f7579ca")]
+[assembly: AssemblyInformationalVersion("2.0.2-dockerlize.1+6.Branch.dockerlize.Sha.54d3a985080cff752c5d5f9cd91b9db264627efc")]
 // 組件的版本資訊是由下列四項值構成:
 //
 //      主要版本

+ 4 - 2
EVCB_OCPP.WEBAPI/Services/HttpClientService.cs

@@ -59,8 +59,10 @@ namespace EVCB_OCPP.WEBAPI.Services
           {
               return new HttpClientHandler
               {
-                  MaxConnectionsPerServer = _maxConnectionsPerServer
-
+                  MaxConnectionsPerServer = _maxConnectionsPerServer,
+                  ClientCertificateOptions = ClientCertificateOption.Manual,
+                  ServerCertificateCustomValidationCallback =
+                    (httpRequestMessage, cert, certChain, policyErrors) => true
               };
           }));
 

+ 51 - 12
EVCB_OCPP.WEBAPI/Services/InternalHttpClient.cs

@@ -1,4 +1,5 @@
 using EVCB_OCPP.WEBAPI.Models.WebAPI;
+using Microsoft.Extensions.Configuration;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using System;
@@ -6,6 +7,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Security.Cryptography;
+using System.Security.Policy;
+using System.ServiceModel.Channels;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -13,20 +16,45 @@ namespace EVCB_OCPP.WEBAPI.Services
 {
     public class InternalHttpClient
     {
-        private HttpClientService httpClient = new HttpClientService();
+        private const string DockerSelfUrl = "{0}://host.docker.internal:{1}";
+        private readonly HttpClientService httpClient;
+        private readonly bool isInDocker;
 
-        async public Task<InternalHttpResult> Post(string url, Dictionary<string, string> headers, object requestBody, string saltkey)
+        public InternalHttpClient(IConfiguration configuration)
+        {
+            httpClient = new HttpClientService();
+            isInDocker = !string.IsNullOrEmpty(configuration["DOTNET_RUNNING_IN_CONTAINER"]);
+        }
+
+        async public Task<InternalHttpResult> Post(string baseUrl, string resource, Dictionary<string, string> headers, object requestBody, string saltkey)
         {
             InternalHttpResult result = new InternalHttpResult() { Success = false };
+            string url = GetRedirctedUrl(baseUrl, resource);
+            string responseMsg = "";
 
             try
             {
                 string body = PreAction(url, ref headers, requestBody, saltkey);
-                var _response = await httpClient.PostJsonAsync(url, body, headers);
-                if (_response.IsSuccessStatusCode)
+                HttpResponse _response = await httpClient.PostJsonAsync(url, body, headers);
+                responseMsg = _response.Response;
+                JObject jo = null;
+
+                try
                 {
-                    JObject jo = JObject.Parse(_response.Response);
+                    jo = JObject.Parse(responseMsg);
+                }
+                catch
+                {
+                    result.Status = _response.StatusCode;
+                    result.Success = _response.IsSuccessStatusCode;
+                    result.Message = _response.Response;
+                    result.Exception = _response.Exception;
+
+                    return result;
+                }
 
+                if (_response.IsSuccessStatusCode)
+                {
                     if (jo.ContainsKey("SerialNo"))
                     {
                         string _SerialNo = jo["SerialNo"].Value<string>();
@@ -42,8 +70,6 @@ namespace EVCB_OCPP.WEBAPI.Services
                 }
                 else
                 {
-                    JObject jo = JObject.Parse(_response.Response);                   
-
                     if (jo.ContainsKey("Message"))
                     {
                         string _Message = jo["Message"].Value<string>();
@@ -55,7 +81,7 @@ namespace EVCB_OCPP.WEBAPI.Services
                         int _ErrorCode = jo["Code"].Value<int>();
                         result.ErrorCode = _ErrorCode;
                     }
-                }               
+                }
 
                 result.Status = _response.StatusCode;
                 result.Success = _response.IsSuccessStatusCode;
@@ -71,10 +97,10 @@ namespace EVCB_OCPP.WEBAPI.Services
             return result;
         }
 
-        async public Task<InternalHttpResult> Get(string url, Dictionary<string, string> headers, string saltkey)
+        async public Task<InternalHttpResult> Get(string baseUrl, string resource, Dictionary<string, string> headers, string saltkey)
         {
-
             InternalHttpResult result = new InternalHttpResult() { Success = false };
+            string url = GetRedirctedUrl(baseUrl, resource);
 
             try
             {
@@ -128,9 +154,10 @@ namespace EVCB_OCPP.WEBAPI.Services
             return result;
         }
 
-        async public Task<InternalHttpResult> Delete(string url, Dictionary<string, string> headers, string saltkey)
+        async public Task<InternalHttpResult> Delete(string baseUrl, string resource, Dictionary<string, string> headers, string saltkey)
         {
             InternalHttpResult result = new InternalHttpResult() { Success = false };
+            string url = GetRedirctedUrl(baseUrl, resource);
 
             try
             {
@@ -184,9 +211,10 @@ namespace EVCB_OCPP.WEBAPI.Services
             return result;
         }
 
-        async public Task<InternalHttpResult> Put(string url, Dictionary<string, string> headers, object requestBody, string saltkey)
+        async public Task<InternalHttpResult> Put(string baseUrl, string resource, Dictionary<string, string> headers, object requestBody, string saltkey)
         {
             InternalHttpResult result = new InternalHttpResult() { Success = false };
+            string url = GetRedirctedUrl(baseUrl, resource);
 
             try
             {
@@ -276,6 +304,17 @@ namespace EVCB_OCPP.WEBAPI.Services
             return BitConverter.ToString(result).Replace("-", "").ToLower();
         }
 
+        private string GetRedirctedUrl(string baseUrl, string resource)
+        {
+            string url = baseUrl;
+            if (isInDocker)
+            {
+                var baseUri = new Uri(url);
+                url = string.Format(DockerSelfUrl, baseUri.Scheme, baseUri.Port);
+            }
+            url = url + resource;
+            return url;
+        }
     }
 
     public class InternalHttpResult : InternalGenericResponse

+ 72 - 0
EVCB_OCPP.WEBAPI/Services/InternalHttpResultConvert.cs

@@ -0,0 +1,72 @@
+using Newtonsoft.Json.Linq;
+using System.Globalization;
+using System.Net.Http;
+using System.Reflection.PortableExecutable;
+using System.Security.Policy;
+using System;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Http;
+using System.Net;
+using Newtonsoft.Json;
+
+namespace EVCB_OCPP.WEBAPI.Services
+{
+    public static class InternalHttpResultConvert
+    {
+        public static InternalHttpResult Convert(ObjectResult from)
+        {
+            InternalHttpResult result = new InternalHttpResult() { Success = false };
+
+            try
+            {
+                var isSuccess = new HttpResponseMessage((HttpStatusCode)from.StatusCode).IsSuccessStatusCode;
+                if (isSuccess)
+                {
+                    JObject jo = JObject.Parse(JsonConvert.SerializeObject(from.Value));
+
+                    if (jo.ContainsKey("SerialNo"))
+                    {
+                        string _SerialNo = jo["SerialNo"].Value<string>();
+                        result.SerialNo = _SerialNo;
+                    }
+
+                    if (jo.ContainsKey("Message"))
+                    {
+                        string _Message = jo["Message"].Value<string>();
+                        result.Message = _Message;
+                    }
+
+                }
+                else
+                {
+                    JObject jo = JObject.Parse(JsonConvert.SerializeObject(from.Value));
+
+                    if (jo.ContainsKey("Message"))
+                    {
+                        string _Message = jo["Message"].Value<string>();
+                        result.Message = _Message;
+                    }
+
+                    if (jo.ContainsKey("Code"))
+                    {
+                        int _ErrorCode = jo["Code"].Value<int>();
+                        result.ErrorCode = _ErrorCode;
+                    }
+                }
+
+                result.Status = (HttpStatusCode)from.StatusCode;
+                result.Success = isSuccess;
+                //result.Message = (string)from.Value?.ToString();
+                //result.Exception = from;//.Exception;
+
+
+            }
+            catch (Exception ex)
+            {
+                result.Exception = ex;
+            }
+
+            return result;
+        }
+    }
+}

+ 4 - 0
EVCB_OCPP.WEBAPI/Startup.cs

@@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
+using Microsoft.AspNetCore.Server.Kestrel.Core;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
@@ -35,6 +36,7 @@ namespace EVCB_OCPP.WEBAPI
         public void ConfigureServices(IServiceCollection services)
         {
             services.AddControllersWithViews(ConfigureMvcOptions)
+                .AddControllersAsServices()
                 // Newtonsoft.Json is added for compatibility reasons
                 // The recommended approach is to use System.Text.Json for serialization
                 // Visit the following link for more guidance about moving away from Newtonsoft.Json to System.Text.Json
@@ -57,6 +59,7 @@ namespace EVCB_OCPP.WEBAPI
 
             services.AddScoped<CPOAuthentication>();
             services.AddScoped<InernalAuthentication>();
+            services.AddScoped<InternalHttpClient>();
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -72,6 +75,7 @@ namespace EVCB_OCPP.WEBAPI
                 app.UseExceptionHandler("/Home/Error");
             }
 
+            app.EnableRequestBodyRewind();
             app.UseMiddleware<ExceptionMiddleware>();
             app.UseMiddleware<APILogMiddleware>();
 

+ 7 - 7
EVCB_OCPP.WEBAPI/appsettings.json

@@ -13,12 +13,12 @@
   "UnobtrusiveJavaScriptEnabled": true,
   "StatisticsAPI": "http://ocpp.phihong.com.tw/StatisticsReportApi/",
   "ConnectionStrings": {
-    "Main20DBContext": "data source=172.1.0.131;initial catalog=StandardOCPP20_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
-    "MeterValue20DBContext": "data source=172.1.0.131;initial catalog=StandardOCPP20_MeterValue;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
-    "ConnectionLogDBContext": "data source=172.1.2.187\\SQLSERVER2016;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
-    "MainDBContext": "data source=172.1.2.187\\SQLSERVER2016;initial catalog=StandardOCPP_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
-    "MeterValueDBContext": "data source=172.1.2.187\\SQLSERVER2016;initial catalog=StandardOCPP_MeterValue;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
-    "APILogDBContext": "data source=172.1.2.187\\SQLSERVER2016;initial catalog=StandardOCPP_APILog;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
-    "WebDBContext": "data source=172.1.2.187\\SQLSERVER2016;initial catalog=StandardOCPP_Web;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework"
+    "Main20DBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
+    "MeterValue20DBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
+    "ConnectionLogDBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_ConnectionLog;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
+    "MainDBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_Main;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
+    "MeterValueDBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_MeterValue;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
+    "APILogDBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_APILog;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework",
+    "WebDBContext": "data source=172.1.0.131\\DEV_OCPP_PORTAL;initial catalog=Docker_Web;;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework"
   }
 }