An existing connection was forcibly closed by the remote host

 

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:

Line 48:         
Line 49:         public System.Data.DataTable GetGlobalAddressList() {
Line 51:         }
Line 52:     }

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:

[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
   System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6157192
   System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +134

[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
   System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +300
   System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +26
   System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +265

[WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
   System.Net.HttpWebRequest.GetResponse() +6063239
   System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +48

[CommunicationException: An error occurred while receiving the HTTP response to http://xxx.xxx.com/InsusServices/GAL.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9464975
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   GAL.IGAL.GetGlobalAddressList() +0
   GAL.GALClient.GetGlobalAddressList() in c:\Users\xxxx\AppData\Local\Temp\Temporary ASP.NET Files\insustutorials\3791b6cb\f7905baa\App_WebReferences.wnen5_ok.0.cs:50
   _Default.Page_Load(Object sender, EventArgs e) in d:\Projects\InsusTutorials\Default.aspx.cs:22
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207



 

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全部代码:

ExpandedBlockStart.gif 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;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值