客户端上的Wcf错误 - 长存储过程 [英] Wcf error on client - long stored procedure

查看:127
本文介绍了客户端上的Wcf错误 - 长存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个使用wcf服务连接SQL SERVER 2008R2的ac #win项目。

当服务时调用一个长存储过程,大约10分钟后客户端抛出此异常:



Hi,

I have a c# win project that uses a wcf service to connect the SQL SERVER 2008R2.
When the service calls to a long stored procedure, after ~10 minutes the client throw this exception:

Error in mscorlib Message: The communication object, System.ServiceModel.Security.SecuritySessionClientSettings`1+ClientSecurityDuplexSession
Channel[System.ServiceModel.Channels.IDuplexSessionChannel]





我查看了SQL分析器,发现SQL服务器正在继续运行SP,错误只是在客户端。



你有什么建议吗?



(它发生在生产,在DEV服务和应用程序在同一台服务器,它没有发生)



谢谢,

Efrat



编辑:



我有一份使用[ServiceContract]和[OperationContract]的合约。

服务类执行合约



客户App.Config





I looked on the SQL profiler and saw that the SQL server is continuing run the SP and the error was just in the client side.

Do you have a suggestion why it happened?

(It occurred just on the production, in the DEV the service and the application in the same server and it doesn't occurred)

Thanks,
Efrat



I have a contract that use [ServiceContract] and [OperationContract].
The service class implement the contract

Client App.Config

<endpoint address="net.tcp://localhost/Services/Service.svc"
       binding="netTcpBinding" bindingConfiguration="NetTcpBinding" behaviorConfiguration="normal"
       contract="Services.Contracts.IService" name="IService">
     <identity>



Server Web.Config


Server Web.Config

<service name="Services.Service" behaviorConfiguration="Service1Behavior">
       <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding.WindowsAuth" contract=".Services.Contracts.IService" behaviorConfiguration="epNormal">
       </endpoint>
       <host>
         <baseAddresses>
           <add baseAddress="net.tcp://localhost/Services/" />
         </baseAddresses>
       </host>
     </service>





我的尝试:



我试图恢复DEV中的错误,所以我将IIS中的空闲时间设置为小于SP运行,此时出现异常在客户端,但SQL SERVER停止运行SP。



What I have tried:

I tried to restore the bug in DEV so I set the idle in the IIS to less than the SP run, after this time there was an exception in the client but also the SQL SERVER stopped run the SP.

推荐答案

在调用WCF服务时添加以下代码:

Add following code when you are calling WCF service:
using(WCFServiceClient client = new WCFServiceClient ())
{ 
    // 15 minutes 30 seconds
    client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 15, 30); 
}





对于客户端,您需要调整a的 sendTimeout 属性绑定元素。对于服务,您需要调整绑定元素的 receiveTimeout 属性。


or
For a client, you would want to adjust the sendTimeout attribute of a binding element. For a service, you would want to adjust the receiveTimeout attribute of a binding element.

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="longTimeoutBinding"

        receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <security mode="None"/>
      </binding>
    </netTcpBinding>
  </bindings>



receiveTimeout - 它包括接收请求/回复服务操作的回复消息。从回调合同方法发送回复消息时,此超时也适用。


sendTimeout - 获取或设置连接保持非活动状态的时间间隔,在此期间没有应用程序消息在被删除之前收到。



以小时:分钟:第二种格式。



其次,您需要提高StoredProcedure的执行性能。执行存储过程不好10分钟。所以只需看看执行计划并添加找出它需要时间的地方。您可以向表中添加一些非聚集索引或优化您的选择查询。



SQL Profiler和SQL Tuning Advisor [ ^ ]


这篇关于客户端上的Wcf错误 - 长存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆