本地测试,远程部署都完全没问题。但是运行一段时间后WCF会出现错误,提示未将对象引用错误,即对象是空的,3到5天出一次异常,
代码结构:
后台:
public class Srv_Bas : Srv.Srv_Master, ISrv_Bas
{
BL_Base bl_BaseInfo;
public Srv_Bas()
{
bl_BaseInfo = new BL_Base(subsystemModuleData.Bas.DBid);
bl_BaseInfo.subsystemModuleData = subsystemModuleData;
masterbl = bl_BaseInfo;
}
} public class Srv_Master
{
public DataTable getDataTable(string strSql)
{
if (masterbl == null)
throw new Exception("masterbl is null");
if (String.IsNullOrWhiteSpace(strSql))
throw new Exception("strSql IsNullOrWhiteSpace");
return masterbl.getDataTable(strSql);
}
}前台:
Type type = srvClient.GetType();
try
{
return (DataTable)type.InvokeMember("getDataTable", System.Reflection.BindingFlags.Default
| System.Reflection.BindingFlags.InvokeMethod, null, srvClient, new object[] { strSql });
}
catch (Exception _e)
{
string InterExceptionMsg="";
if (_e.InnerException !=null)
InterExceptionMsg= _e.InnerException.Message;
throw new Exception("方法getDataTable(" + strSql + ")出错了。\r" + _e.Message + "\rInnerException:" + InterExceptionMsg);
}
代码结构:
后台:
public class Srv_Bas : Srv.Srv_Master, ISrv_Bas
{
BL_Base bl_BaseInfo;
public Srv_Bas()
{
bl_BaseInfo = new BL_Base(subsystemModuleData.Bas.DBid);
bl_BaseInfo.subsystemModuleData = subsystemModuleData;
masterbl = bl_BaseInfo;
}
} public class Srv_Master
{
public DataTable getDataTable(string strSql)
{
if (masterbl == null)
throw new Exception("masterbl is null");
if (String.IsNullOrWhiteSpace(strSql))
throw new Exception("strSql IsNullOrWhiteSpace");
return masterbl.getDataTable(strSql);
}
}前台:
Type type = srvClient.GetType();
try
{
return (DataTable)type.InvokeMember("getDataTable", System.Reflection.BindingFlags.Default
| System.Reflection.BindingFlags.InvokeMethod, null, srvClient, new object[] { strSql });
}
catch (Exception _e)
{
string InterExceptionMsg="";
if (_e.InnerException !=null)
InterExceptionMsg= _e.InnerException.Message;
throw new Exception("方法getDataTable(" + strSql + ")出错了。\r" + _e.Message + "\rInnerException:" + InterExceptionMsg);
}
解决方案 »
- WebBrowser.print() 没反应?
- 如何使代码在Debug下可用,而Release下不可用?
- Σ(西格玛)是怎么计算啊
- 大家帮我出一下注意,顶者有分
- 问个很水的问题...
- asp.net网站设计
- “Graphics”是“命名空间”,但此处被当做“类型”来使用
- 单选按钮和复选框的布局(windows form)
- 今天偶然发现enum里的成员居然可以点出方法列表。我想重构它的ToString(),怎么做呢?
- 讨论:C# + ASP.NET + SQL Server做一个项目管理软件
- 求教!c#指定多声卡(总共6个声卡)!可以同时分别播放不同的MP3音乐。
- 关于NetworkStream.Read方法
1.首先要声明的是正常运行没有问题,过一段时间后发生错误,重新发布WCF又会好,周而复始
2.从出错的信息来看是后台出的错误,很明显InnerException返回的错误,是前台参数没有传送的后台引起的如strSql没有传到后台。因此考虑到是不是长期反射调用WCF后台参数无法传递引起的从另一个帖子看是IIS的问题,但这似乎跟IIS没有直接的关系,因为反射是前台反射的,已加batch="false",效果未知如下是参考链接
http://topic.csdn.net/u/20090524/21/108ec37f-2eb1-4096-8d36-e961cb8cea52.html
这是因为有功能类似的几个类,都要用到getDataTable,因此只有继承基类就不要写几个,所以用到了反射
主要是看看有没有哪位大侠有这方面的经验可以借鉴
你的问题是"未将对象引用错误",我觉得八成还是你代码的问题。这种不定期,不是100%重现的问题不是很容易解决。
我的解决办法是,
1. 测试,写个简单测试端,开线程模拟并发,循环,做大量测试,看是否能够重现。
2. 你有CallStack,知道那个函数出的问题,在函数开始将所有参数写log,问题出现中从log取得数据,对函数进行测试。
<serviceBehaviors>
<behavior name="NetStars.Soft_SecurityPlatform.WcfService.BBsService">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="10000" maxConcurrentInstances="2147483647" maxConcurrentSessions="10000" />
</behavior>
其次就是,前端验证做好了么?sql null 或者 sql 格式有误
WebHost failed to process a request.
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/3323268
Exception: System.ServiceModel.ServiceActivationException: The service '/UnifiedInfos/srvMES/MesSrv.Srv_Mes.svc' cannot be activated due to an exception during compilation. The exception message is: Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.Compilation.DiskBuildResultCache.CacheBuildResult(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart)
at System.Web.Compilation.BuildManager.CacheBuildResultInternal(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart)
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetCompiledCustomString(String virtualPath)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.GetCompiledCustomString(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
--- End of inner exception stack trace ---
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
Process Name: w3wp
Process ID: 18536
http://cheny.sh.blog.163.com/blog/static/49675535201251423549294/
http://stackoverflow.com/questions/5002386/problems-with-notfound-errors-and-compilation-failures