WCF采用 netTcpBinding 发生的Socket errors

最近在项目中采用 Windows service 作为WCF services的宿主, 在服务和客户端的调用上没有发生如何的异常和错误,但是经常发生下述错误:

“System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '10675199.02:48:05.4775807'”

下面是一个解决方案:当使用WCF 服务使用 netTcpBinding 时,需要在客户端代理调用方法close()关闭代理,将服务的实例放回到池中。

WCF服务使用WSHttp或者BasicHttp的时候没有这个问题。

作者: 自由、创新、研究、探索……
出处:http://shanyou.cnblogs.com/
版权:本文版权归作者和博客园共有
转载:欢迎转载,为了保存作者的创作热情,请按要求【转载】,谢谢
要求:未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任
posted @ 2008-09-22 17:28 张善友 阅读(1222) 评论(15) 编辑 收藏

 回复 引用 查看   
#1楼 2008-11-22 12:18 刘将      
请教一下在那边可以把客户端代理调用方法close()关闭代理,我是生成的代码

 回复 引用 查看   
#2楼[楼主] 2008-11-22 12:39 geff zhang      
@刘将
ClientBase有个方法是close,调用这个方法就可以了

 回复 引用 查看   
#3楼 2008-11-22 12:54 刘将      
谢谢你回答,我还是不太明白,比如说Client:ClientBase(ITest)
{
public test1(){}
}
client aa=new client();
aa.test1()前close还是后close呢?总是会总不能使用dispose对像

 回复 引用 查看   
#4楼[楼主] 2008-11-22 15:56 geff zhang      
test1()是个方法吧,写法上有错哦 aa.test1()之后close
 回复 引用 查看   
#5楼 2008-11-24 10:04 刘将      
test1()是一个方法,事实上在在调用test1()时就报错了,还没有close(),所以close()的作用就没有用了。
 回复 引用 查看   
#6楼[楼主] 2008-11-24 21:56 geff zhang      
@刘将
这说明你的test1()有问题了

 回复 引用 查看   
#7楼 2010-01-28 12:00 virus      
WCF服务使用WSHttp或者BasicHttp的时候没有这个问题。

错了吧,我的就是sl3+wcf,使用basicHttpBinding,可是在返回结果中就受到了
System.ServiceModel.CommunicationException

 回复 引用 查看   
#8楼 2010-01-28 12:02 virus      
client.GetCustomerAsync(this._customerId);
client.GetCustomerCompleted += new EventHandler<GetCustomerCompletedEventArgs>(client_GetCustomerCompleted);

这句是不是应该改成


client.GetCustomerCompleted += new EventHandler<GetCustomerCompletedEventArgs>(client_GetCustomerCompleted);
client.GetCustomerAsync(this._customerId);
client.close()
呢,谢谢

 回复 引用 查看   
#9楼 2010-01-28 12:05 virus      
public IList<Customer> GetAllCustomer()
{

IList<Customer> cs = _customerDao.GetAll();
return cs;
}
运行完毕就会报错

system.targetinvocationexception

难道不能用IList吗,断点我看了,cs中是有值的,前几天我这个还好好的跑呢,可是今天

 回复 引用 查看   
#10楼 2010-01-28 12:07 virus      

void client_GetCustomerCompleted(object sender, GetCustomerCompletedEventArgs e)
{
LayoutRoot.DataContext = e.Result;
}

e.Result;报错
System.ServiceModel.CommunicationException
可以提供一些信息吗



 回复 引用 查看   
#11楼 2010-01-28 12:07 virus      
实体类定义

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace Domain.Entity
{
[DataContract]
public class Customer : INotifyPropertyChanged
{
private int _intCustomerId;
private string _strCustomerName;
private string _strCustomerCode;
private CustomerType _CustomerType;
private int _intCustomerTypeId;

[DataMember ]
public virtual int CustomerTypeId
{
get { return _intCustomerTypeId; }
set { _intCustomerTypeId = value; }
}

[DataMember ]
public virtual CustomerType CustomerType
{
get { return this._CustomerType; }
set
{

this._CustomerType = value;
OnPropertyChanged("CustomerType");
}
}

[DataMember]
public virtual int CustomerId
{
get { return this._intCustomerId; }
set
{
this._intCustomerId = value;
OnPropertyChanged("CustomerId");
}
}
[DataMember]
public virtual string CustomerName
{
get { return this._strCustomerName; }
set
{
this._strCustomerName = value; OnPropertyChanged("CustomerName");
}
}
[DataMember]
public virtual string CustomerCode
{
get { return _strCustomerCode; }
set
{
this._strCustomerCode = value;
OnPropertyChanged("CustomerCode");
}
}

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

#endregion
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}

 回复 引用 查看   
#12楼 2010-01-28 12:07 virus      
获取数据使用NHibernate
 回复 引用 查看   
#13楼 2010-01-28 12:09 virus      
有人说web.config要配置成这样,可是配置成这样的话 ,在sl中都不能添加引用
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix ="http://sl.kimbanxcn"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>

我就该回去了

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" >
</serviceHostingEnvironment>

 回复 引用 查看   
#14楼[楼主] 2010-01-28 12:57 geff zhang      
@virus
贴了这么多,不知道你要说明什么问题

 回复 引用 查看   
#15楼 2012-02-07 11:08 开国伟人      
不行啊,哥,
显示关闭还是不行