Server Error in '/InsusTutorials' Application.
An existing connection was forcibly closed by the remote host
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Source Error:
|
Source File: c:\Users\xxxxx\AppData\Local\Temp\Temporary ASP.NET Files\insustutorials\3791b6cb\f7905baa\App_WebReferences.wnen5_ok.0.cs Line: 50
Stack Trace:
|
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.431
你可以看到此篇,http://www.cnblogs.com/insus/archive/2011/08/30/2159776.html 这个Service返回的是string[]数据类型,今天Insus.NET尝试再次修改它,因为需要邮件的昵称与邮件地址,因此,把它改为返回一个DataTable,编译发布之后,程序去读取这个Services时,就出现上面这个错误。
WCF参考文章与网上很多网友的说法, WCF不能返回一个DataTable数据类型。
不过,Insus.NET的解决方法,很简单,只是添加一句:
dataTable.TableName
=
"
GAL
"
;
//
添加此句,给这个DataTable一个表名。
Service.svc全部代码:
GetGlobalAddressList
public
DataTable GetGlobalAddressList()
{
DirectorySearcher objsearch = new DirectorySearcher();
string strrootdse = objsearch.SearchRoot.Path;
DirectoryEntry objdirentry = new DirectoryEntry(strrootdse);
objsearch.Filter = " (& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) )) " ;
objsearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
objsearch.PropertiesToLoad.Add( " cn " );
objsearch.PropertiesToLoad.Add( " Mail " );
objsearch.PropertyNamesOnly = true ;
objsearch.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
objsearch.Sort.PropertyName = " cn " ;
objsearch.Sort.PropertyName = " Mail " ;
SearchResultCollection colresults = objsearch.FindAll();
DataTable dataTable = new DataTable();
dataTable.TableName = " GAL " ; // 添加此句,给这个DataTable一个表名。
DataRow dataRow;
dataTable.Columns.Add( new DataColumn( " nickname " , typeof ( string )));
dataTable.Columns.Add( new DataColumn( " mail " , typeof ( string )));
foreach (SearchResult objresult in colresults)
{
dataRow = dataTable.NewRow();
dataRow[ " nickname " ] = objresult.GetDirectoryEntry().Properties[ " cn " ].Value;
dataRow[ " mail " ] = objresult.GetDirectoryEntry().Properties[ " Mail " ].Value;
dataTable.Rows.Add(dataRow);
}
objsearch.Dispose();
return dataTable;
}
{
DirectorySearcher objsearch = new DirectorySearcher();
string strrootdse = objsearch.SearchRoot.Path;
DirectoryEntry objdirentry = new DirectoryEntry(strrootdse);
objsearch.Filter = " (& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) )) " ;
objsearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
objsearch.PropertiesToLoad.Add( " cn " );
objsearch.PropertiesToLoad.Add( " Mail " );
objsearch.PropertyNamesOnly = true ;
objsearch.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
objsearch.Sort.PropertyName = " cn " ;
objsearch.Sort.PropertyName = " Mail " ;
SearchResultCollection colresults = objsearch.FindAll();
DataTable dataTable = new DataTable();
dataTable.TableName = " GAL " ; // 添加此句,给这个DataTable一个表名。
DataRow dataRow;
dataTable.Columns.Add( new DataColumn( " nickname " , typeof ( string )));
dataTable.Columns.Add( new DataColumn( " mail " , typeof ( string )));
foreach (SearchResult objresult in colresults)
{
dataRow = dataTable.NewRow();
dataRow[ " nickname " ] = objresult.GetDirectoryEntry().Properties[ " cn " ].Value;
dataRow[ " mail " ] = objresult.GetDirectoryEntry().Properties[ " Mail " ].Value;
dataTable.Rows.Add(dataRow);
}
objsearch.Dispose();
return dataTable;
}