我开发了一个webservice的方法(GetDServices),它调用一个返回字符串结果的函数(GetResource)。
在对函数的第一次调用中,Culture参数的值为' ca-ES',并完美地检索它。
我第二次调用该方法时,该函数接收带有值' en-US'的参数,但第一次调用的值为ca-ES'仍然存在。
我不明白为什么会这样。 我已经调试了,方法调用的值正确到达。
如果我重新启动,第一次运行良好。
我编辑此代码,现在发布完整代码。
经过测试,我尝试分配新的变量(测试和测试2),当我调用方法时,我看到,因为赋值(test& test2)运行良好,但是当我从数组赋值调用方法时,在第二次调用中保持第一价值。
我的方法:
[WebMethod]
#region GetServices
public ResultDTO GetServices(
LoginDTO login,
string enterprise,
string culture,
out List<Services> Services
)
{
Bootstrapper.TryInit();
LogHelper.DumpParams("WS.GetServices", login, enterprise);
// Inicialización de salida.
Services = new List<Services>();
try
{
// LOGIN VALIDATION
User user;
var result = ValidationHelper.ValidateLogin(login, out user);
if (result != null)
{
return LogHelper.DumpResult("WS.GetServices", result);
}
// LOGIN VALIDATION END
// QUERY SERVICES
var queryservices = Bootstrapper.Context.GetRepository<Service, long>()
.Query().Where(x => x.EnterpriseServiceRelationVigence.Any(y => y.Enterprise.NIF == enterprise));
if (queryservices == null)
{
return LogHelper.DumpResult("WS.GetServices", new ResultDTO(ErrorCodes.SERVICES_NOT_FOUND));
}
// this vars has correct value after assignation
string test = culture; // <- here First time has "ca-ES" and second time has "en-US"
string test2 = GetResource(culture, "sample" ); // <- here First time has "ca-Es" and second time has "en-US"
Services = queryservices.Select(x => new Services
{
IdService = x.Id,
Name = x.Name,
ShortDescription = GetResource(test, x.ResourceKey + "Description"),
Description = GetResource(test, x.ResourceKey + "Comment"),
ImageButton = x.ImageButton,
ImageButtonDisabled = x.ImageButtonDisabled,
ImageButtonHome = x.ImageButtonHome,
ColorTextoHome = x.ColorTextoHome,
}
).ToList();
return LogHelper.DumpResult("WS.GetServices", new ResultDTO());
}
catch (Exception ex)
{
Logger.Log.Error(() => ex.ToString());
return LogHelper.DumpResult("WS.GetServices", new ResultDTO(ErrorCodes.GENERIC_ERROR));
}
}
#endregion
我的功能:
static string GetResource(string Culture, string ResourceKey)
{
// When this function its called, from test2 assignation running well.
// but when this function its called from
// ShortDescription = GetResource(test, x.ResourceKey + "Description"),
// or
// Description = GetResource(test, x.ResourceKey + "Comment"),
// then remained the value of first call.
if (Culture.IsNullOrEmpty()) { Culture = "es-ES"; }
var queryservices = Bootstrapper.Context.GetRepository<Resource, string>()
.Query().Where(x => x.ResourceKey == ResourceKey && x.CultureKey == Culture);
if (!queryservices.IsNullOrEmpty()) // Usuari Generic
{
return queryservices.Select(x => x.ResourceValue).FirstOrDefault();
}
return string.Empty;
}
答案 0 :(得分:0)
除非您可以发布GetDServices
方法正文的完整代码,(假设此方法的culture
的原始值正确),请检查您是否有任何重新分配调用culture
之前的GetResource
变量,即以下代码
// Inicialization
...
// Login validation
...
// End Login Validation
...