我正在使我们的大量 Web 服务可用于 AJAX 调用。我已将其添加[System.Web.Script.Services.ScriptService]
到每个服务中。我们有一个已注册的 HttpModule,它初始化了一些我们经常在 IHttpModule.Init 覆盖中用于日志记录和国际化的对象。似乎在我向任何 Web 方法发出 SOAP 请求时调用了 IHttpModule.Init,但在我向任何 Web 方法发出 JSON 请求时却没有。我已经通过在调用文件时写入文件来确认这一点。
通过 javascript 代理 (AJAX) 调用 .Net Web 服务时是否使用 HttpModules?如果是这样,我是否缺少某种配置?相关代码位包括在下面。
-科林-
网络配置:
<httpModules><add name="GlobalApplicationModule" type="Common.GlobalApplicationModule, Common"/></httpModules>
HTTPModules.cs:
class GlobalApplicationModule : IHttpModule
{
public void Dispose()
{
Internationalization.LanguageProvider.ReleaseAllResources();
}
public void Init(HttpApplication application)
{
// DEBUG: Confirm that this method is called
StreamWriter writer = new StreamWriter("c:\\deleteme-HTTP_module_test.txt");
writer.WriteLine("Init called.");
writer.Close();
// Initialize logger
Common.Logger.Initialize("LogAssemblyPath", "LogClassName");
Common.CentralConfiguration.CreateConfiguration(new Common.CentralizedStrategy());
// Initialize language provider
if (!Internationalization.LanguageProvider.Initialized)
{
try
{
string debug = System.Configuration.ConfigurationManager.AppSettings["debugInternationalization"];
string languageAssemblyLocation = System.Configuration.ConfigurationManager.AppSettings["LanguageAssemblyLocation"];
string languageAssemblyBaseName = System.Configuration.ConfigurationManager.AppSettings["LanguageAssemblyBaseName"];
languageAssemblyLocation = System.Web.HttpContext.Current.Server.MapPath(languageAssemblyLocation);
Internationalization.LanguageProvider.Init(languageAssemblyLocation, languageAssemblyBaseName, false);
if (debug != null && bool.Parse(debug))
{
Internationalization.LanguageProvider.PrefixText = "*";
}
}
catch (Exception x)
{
Common.Logger.Instance.LogError("Could not intialize assembly language provider. Error: " + x.Message);
}
}
}
}