静态类中的WCF服务访问

时间:2016-05-09 11:17:15

标签: c# .net wcf automapper wcf-client

public static IEnumerable<HospitalEntities> GetAllHospitalDetails(HospitalRequest hospitalRequest)
{
    CommonClass commonClass = new CommonClass();
    try
    {
        return Mapper.Map<IEnumerable<HospitalDto>, List<HospitalEntities>>(new HealthServiceClient().GetAllHospitalDetails(new HospitalRequestDto
        {
            ApplicationContext = Mapper.Map<ApplicationContext, ApplicationContextDto>(commonClass.ApplicationContext),
            TenantContext = Mapper.Map<TenantContext, TenantContextDto>(commonClass.TenantContext),
            UserContext = Mapper.Map<UserContext, UserContextDto>(commonClass.UserContext),
            SelectedTenantId = hospitalRequest.SelectedTenantId,
            hospitalDto = Mapper.Map<HospitalEntities, HospitalDto>(hospitalRequest.hospitals)
        }).hospitalResponseDto);
    }
    catch (Exception Ex)
    {
        ExceptionPolicy.HandleException(Ex, ExceptionPolicies.UI_POLICY, (Int32)ExceptionConstant.EventId.ERR_UI_HEALTH_HealthServiceHelper_GetAllHospitalDetails, "ManageVaccinationMaster.aspx", Conversion.ConvertToString(commonClass.TenantContext.TenantId), Conversion.ConvertToString(commonClass.TenantContext.ClientCode), Conversion.ConvertToString(commonClass.UserContext.UserId));
        throw Ex;
    }
}

这种方法对吗? WCF连接是否仍然打开?从静态类访问WCF服务是否合适?

0 个答案:

没有答案