这两天遇到一个问题,调用一个WCF服务的时候,服务器端正常的返回了数据,但是客户端却遇到了一场

System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly.

直接调试查看堆栈信息也没有弄清楚怎么回事。最后上网搜了一下,发现一个获取WCF运行信息的工具。

1.打开服务器端wcf服务的web.config配置文件并添加如下的信息:

<system.diagnostics>
 <!-- This logging is great when WCF does not work. -->
 <sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
   <listeners>
    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\temp\traces.svclog" />
   </listeners>
  </source>
 </sources>
</system.diagnostics>

 

2.调用wcf服务,然后你会发现在c:\temp目录下多了一个叫traces.svclog的文件。

3.使用vs的command prompt打开svctraceviewer.exe,然后选择查看上面的svclog文件。你会发现很多wcf服务调用的信息,其中标红色的表示出现了错误。

 

使用svctraceviewer查看WCF服务异常信息

相关文章:

  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2021-06-16
  • 2021-12-30
  • 2022-03-01
猜你喜欢
  • 2021-10-30
  • 2021-12-14
  • 2021-09-19
  • 2021-06-05
  • 2021-08-04
相关资源
相似解决方案