我得到错误“的现有连接被强行关闭远程主机”后,我关闭客户端程序。 我加入这个代码,以确保当程序被关闭,关闭客户端连接。
我也有一个按钮来关闭客户端和按钮的作品没有一个错误。
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
client.Close();
}
catch (CommunicationException ex)
{
client.Abort();
}
catch (TimeoutException ex)
{
client.Abort();
}
catch (Exception ex)
{
client.Abort();
throw ex;
}
}
难道我在这里错过了什么? 这是堆栈跟踪:
< StackTrace>
bei System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()
bei System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)
bei System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender, SocketAsyncEventArgs e)
bei System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
bei System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
bei System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
bei System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
< /StackTrace>
我希望堆栈跟踪帮助别人帮我:d我使用nettcp,只有当我关闭程序时出现错误。
谢谢,曼努埃尔
更新:WCF配置:服务器:
<serviceBehaviors>
<behavior name="MyBehaviour">
<serviceMetadata/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<services>
<service name="Service" behaviorConfiguration="MyBehaviour">
<host>
</host>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="TCP" contract="IService"/>
<endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<netTcpBinding>
<binding name="TCP" portSharingEnabled="true" receiveTimeout="01:30:00" sendTimeout="01:10:00"
openTimeout="00:10:00" closeTimeout="00:10:00">
<security mode="None"/>
</binding>
</netTcpBinding>
客户:
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService" receiveTimeout="01:30:00" sendTimeout="01:00:00" openTimeout="00:10:00" closeTimeout="00:10:00">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://host/Service.svc"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService"
contract="ServiceRef.IService" name="NetTcpBinding_IService" />
</client>
</system.serviceModel>
</configuration>