public System.Threading.Tasks.Task <CommonSoapService.ServiceResponse> ServiceAsync(string username, string password, string typeofservice)
 {
     CommonSoapService.ServiceRequest inValue = new CommonSoapService.ServiceRequest();
     inValue.Body               = new CommonSoapService.ServiceRequestBody();
     inValue.Body.username      = username;
     inValue.Body.password      = password;
     inValue.Body.typeofservice = typeofservice;
     return(((CommonSoapService.commonserviceRD3Soap)(this)).ServiceAsync(inValue));
 }
 System.Threading.Tasks.Task <CommonSoapService.ServiceResponse> CommonSoapService.commonserviceRD3Soap.ServiceAsync(CommonSoapService.ServiceRequest request)
 {
     return(base.Channel.ServiceAsync(request));
 }
Ejemplo n.º 3
0
        public async Task <ActionResult <HttpResultModel> > Get(string typeOfService)
        {
            HttpResultModel httpResult = new HttpResultModel();

            try
            {
                CommonSoapService.commonserviceRD3SoapClient            service        = new CommonSoapService.commonserviceRD3SoapClient();
                ChannelFactory <CommonSoapService.commonserviceRD3Soap> channelFactory = service.ChannelFactory;
                CommonSoapService.commonserviceRD3Soap channel        = channelFactory.CreateChannel();
                CommonSoapService.ServiceRequest       serviceRequest = new CommonSoapService.ServiceRequest
                {
                    Body = new CommonSoapService.ServiceRequestBody
                    {
                        username      = soapUsername,
                        password      = soapPassword,
                        typeofservice = typeOfService
                    }
                };

                CommonSoapService.ServiceResponse responseMessage = await channel.ServiceAsync(serviceRequest);

                CommonSoapService.common soapResult = responseMessage?.Body.ServiceResult;

                List <Common> listCommon  = new List <Common>();
                Model.Common  commonModel = new Model.Common(soapResult);

                if (soapResult != null)
                {
                    int countRecord = 0;

                    if (typeOfService == VRTCommonService)
                    {
                        countRecord = soapResult.vBusinessTypeCode.Count();
                    }
                    else if (typeOfService == VATCommonService)
                    {
                        countRecord = soapResult.vAmphurCode.Count();
                    }

                    for (int index = 0; index < countRecord; index++)
                    {
                        Common common = new Common();
                        if (typeOfService == VRTCommonService)
                        {
                            common = new Common
                            {
                                typeofservice = typeOfService,
                                // VRTCommon
                                vBusinessTypeCode = soapResult.vBusinessTypeCode[index]?.ToString(),
                                vBusinessTypeName = soapResult.vBusinessTypeName[index]?.ToString(),
                                vStreetCode       = soapResult.vStreetCode[index]?.ToString(),
                                vStreetName       = soapResult.vStreetName[index]?.ToString(),
                                vVRTProvinceCode  = soapResult.vVRTProvinceCode[index]?.ToString(),
                                vVRTProvinceName  = soapResult.vVRTProvinceName[index]?.ToString(),

                                vMessErr = soapResult.vMessErr.Count() > 0 ? soapResult.vMessErr[index]?.ToString() : null,
                            };
                            listCommon.Add(common);
                        }
                        else if (typeOfService == VATCommonService)
                        {
                            common = new Common
                            {
                                typeofservice = typeOfService,
                                // VATCommon
                                vAmphurCode   = soapResult.vAmphurCode[index]?.ToString(),
                                vProvinceCode = soapResult.vProvinceCode[index]?.ToString(),
                                vDescription  = soapResult.vDescription[index]?.ToString(),

                                vMessErr = soapResult.vMessErr.Count() > 0 ? soapResult.vMessErr[index]?.ToString() : null,
                            };
                            listCommon.Add(common);
                        }
                    }
                }

                httpResult.SetPropertyHttpResult(httpResult, true, "", "", StatusCodes.Status200OK, listCommon);
            }
            catch (Exception ex)
            {
                httpResult.SetPropertyHttpResult(httpResult, false, "API Error", ex.Message, StatusCodes.Status500InternalServerError);
            }

            return(Ok(httpResult));
        }