【发布时间】:2015-07-01 11:47:05
【问题描述】:
这个问题与System.ServiceModel.CommunicationException: The underlying connection was closed 重复,但它没有解决我的问题。
我正在使用写入和读取数据库的 WCF 服务。但在某些情况下,请求会以 CommunicationException 取消,表示底层连接已关闭。没有提供更多细节。
我启用了跟踪,但日志没有显示有关此请求的条目。我尝试将MaxItemsInObjectGraph 设置为 65535,但没有任何改变。可能是我的配置有问题,有人可以看看吗?
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource"
switchValue="Information, ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="Error.svclog" />
</sharedListeners>
</system.diagnostics>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- Legen Sie die Werte unten vor der Bereitstellung auf "false" fest, um die Veröffentlichung von Metadateninformationen zu vermeiden. -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- Damit in Fehlern Ausnahmedetails zum Debuggen angezeigt werden, legen Sie den Wert unten auf "true" fest. Legen Sie ihn vor der Bereitstellung auf "false" fest, um die Veröffentlichung von Ausnahmeinformationen zu vermeiden. -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<!-- Umgeht eine CommunicationException, die auftritt, wenn der ObjectGraph überläuft -->
<dataContractSerializer maxItemsInObjectGraph="65535"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDBUpdater"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="StreamedResponse"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
<binding maxReceivedMessageSize="2147483647" allowCookies="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<remove scheme="http" />
<add scheme="http" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDBUpdater" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
Um das Stammverzeichnis der Webanwendung beim Debuggen auszuwählen, legen Sie den Wert unten auf "true" fest.
Legen Sie ihn vor der Bereitstellung auf "false" fest, um die Veröffentlichung von Informationen über den Webanwendungsordner zu vermeiden.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDBUpdater" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" useDefaultWebProxy="true" />
<binding allowCookies="true" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.1.58.48/DBUpdate/UpdateService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDBUpdater"
contract="UpdateService.IDBUpdater" />
</client>
</system.serviceModel>
</configuration>
我对 WCF 配置不是很熟悉。有什么问题吗?或者为什么我不断收到此错误消息?
代码示例:
string cmd = @"SELECT trainer.TID, anrede.Anrede, trainer.Titel, trainer.Vorname, trainer.Nachname, trainer.Festnetz, trainer.Mobil, trainer.Email, trainer.Trainerstatus, trainer.Honorar
FROM trainer
left join anrede on trainer.Anrede = anrede.ID
Group by trainer.TID";
var client = new DBUpdaterClient();
dt = client.ExecuteReaderUGV(Helpers.GetUsername(), cmd);
调用ExecuteReaderUGV()后出现错误,生成的数据表对象应该有大约3500个条目。对于较小的数据表 (
错误信息: 底层连接已关闭:连接意外关闭。
更新:
我们将问题追溯到关键字left join。当替换为inner join 时,它可以正常工作。但是,我们不清楚为什么会发生这种情况。当我们在没有 Web 服务的情况下访问数据库并使用 left join 执行 sql 命令时,它可以工作。当我们使用网络服务时,它不会。
更新二:
问题在于left join 处的条件:如果无法评估条件(例如一个值不存在),Web 服务调用会以Communication Exception 应答。有人知道更多吗?
【问题讨论】:
-
您能否提供一个完整调用给您问题的服务的代码示例?
-
我已经编辑了问题并添加了更多详细信息。
标签: c# web-services wcf exception web-config